c#文件操作的一个小程序

因为需要,编写了下面的小软件,对平常人没啥用,但思路还是有点价值的
功能是把一个目录里边的歌曲按照名字分类放入目录
load_pic2?verify=7SjOMIHU67KCKu%2BYPUqo0w%3D%3D
 
   
None.gif  
None.gif
using  System; 
None.gif
using  System.Drawing; 
None.gif
using  System.Collections; 
None.gif
using  System.ComponentModel; 
None.gif
using  System.Windows.Forms; 
None.gif
using  System.Data; 
None.gif
using  System.IO; 
None.gif
None.gif
namespace  filemanger 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary> 
InBlock.gif    
/// Form1 的摘要说明。 
ExpandedSubBlockEnd.gif    
/// </summary> 

InBlock.gif    public class Form1 : System.Windows.Forms.Form 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif        
private System.Windows.Forms.RichTextBox show; 
InBlock.gif        
private System.Windows.Forms.Button showfiles; 
InBlock.gif        
private System.Windows.Forms.Label number; 
InBlock.gif        
private System.Windows.Forms.Label l; 
InBlock.gif        
private System.Windows.Forms.Button move; 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 必需的设计器变量。 
ExpandedSubBlockEnd.gif        
/// </summary> 

InBlock.gif        private System.ComponentModel.Container components = null
InBlock.gif
InBlock.gif        
public Form1() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
// 
InBlock.gif            
// Windows 窗体设计器支持所必需的 
InBlock.gif            
// 
InBlock.gif
            InitializeComponent(); 
InBlock.gif
InBlock.gif            
// 
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码 
InBlock.gif            
// 
ExpandedSubBlockEnd.gif
        }
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 清理所有正在使用的资源。 
ExpandedSubBlockEnd.gif        
/// </summary> 

InBlock.gif        protected override void Dispose( bool disposing ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
if( disposing ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
if (components != null)  
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    components.Dispose(); 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
base.Dispose( disposing ); 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改 
InBlock.gif        
/// 此方法的内容。 
ExpandedSubBlockEnd.gif        
/// </summary> 

InBlock.gif        private void InitializeComponent() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
this.show = new System.Windows.Forms.RichTextBox(); 
InBlock.gif            
this.showfiles = new System.Windows.Forms.Button(); 
InBlock.gif            
this.number = new System.Windows.Forms.Label(); 
InBlock.gif            
this.l = new System.Windows.Forms.Label(); 
InBlock.gif            
this.move = new System.Windows.Forms.Button(); 
InBlock.gif            
this.SuspendLayout(); 
InBlock.gif            
//  
InBlock.gif            
// show 
InBlock.gif            
//  
InBlock.gif
            this.show.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)  
InBlock.gif                
| System.Windows.Forms.AnchorStyles.Left)  
InBlock.gif                
| System.Windows.Forms.AnchorStyles.Right))); 
InBlock.gif            
this.show.Location = new System.Drawing.Point(88); 
InBlock.gif            
this.show.Name = "show"
InBlock.gif            
this.show.ReadOnly = true
InBlock.gif            
this.show.Size = new System.Drawing.Size(432216); 
InBlock.gif            
this.show.TabIndex = 0
InBlock.gif            
this.show.Text = "电击开始显示文件信息"
InBlock.gif            
//  
InBlock.gif            
// showfiles 
InBlock.gif            
//  
InBlock.gif
            this.showfiles.Location = new System.Drawing.Point(8232); 
InBlock.gif            
this.showfiles.Name = "showfiles"
InBlock.gif            
this.showfiles.Size = new System.Drawing.Size(8823); 
InBlock.gif            
this.showfiles.TabIndex = 1
InBlock.gif            
this.showfiles.Text = "显示文件信息"
InBlock.gif            
this.showfiles.Click += new System.EventHandler(this.showfiles_Click); 
InBlock.gif            
//  
InBlock.gif            
// number 
InBlock.gif            
//  
InBlock.gif
            this.number.ForeColor = System.Drawing.Color.Red; 
InBlock.gif            
this.number.Location = new System.Drawing.Point(328240); 
InBlock.gif            
this.number.Name = "number"
InBlock.gif            
this.number.TabIndex = 2
InBlock.gif            
this.number.Click += new System.EventHandler(this.number_Click); 
InBlock.gif            
//  
InBlock.gif            
// l 
InBlock.gif            
//  
InBlock.gif
            this.l.Location = new System.Drawing.Point(208240); 
InBlock.gif            
this.l.Name = "l"
InBlock.gif            
this.l.Size = new System.Drawing.Size(12023); 
InBlock.gif            
this.l.TabIndex = 3
InBlock.gif            
this.l.Text = "符合要求的mp3数目"
InBlock.gif            
//  
InBlock.gif            
// move 
InBlock.gif            
//  
InBlock.gif
            this.move.Enabled = false
InBlock.gif            
this.move.Location = new System.Drawing.Point(120232); 
InBlock.gif            
this.move.Name = "move"
InBlock.gif            
this.move.TabIndex = 4
InBlock.gif            
this.move.Text = "开始移动"
InBlock.gif            
this.move.Click += new System.EventHandler(this.move_Click); 
InBlock.gif            
//  
InBlock.gif            
// Form1 
InBlock.gif            
//  
InBlock.gif
            this.AutoScaleBaseSize = new System.Drawing.Size(614); 
InBlock.gif            
this.ClientSize = new System.Drawing.Size(456270); 
InBlock.gif            
this.Controls.Add(this.move); 
InBlock.gif            
this.Controls.Add(this.l); 
InBlock.gif            
this.Controls.Add(this.number); 
InBlock.gif            
this.Controls.Add(this.showfiles); 
InBlock.gif            
this.Controls.Add(this.show); 
InBlock.gif            
this.Name = "Form1"
InBlock.gif            
this.Text = "Form1"
InBlock.gif            
this.ResumeLayout(false); 
InBlock.gif
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif        
#endregion
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 应用程序的主入口点。 
ExpandedSubBlockEnd.gif        
/// </summary> 

InBlock.gif        [STAThread] 
InBlock.gif        
static void Main()  
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            Application.Run(
new Form1()); 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void showfiles_Click(object sender, System.EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    show.Text=""
InBlock.gif            show.ReadOnly
=true
InBlock.gif            DirectoryInfo dir 
= new DirectoryInfo(Application.StartupPath);//获取程序目录 
InBlock.gif
            FileInfo[] mp3files = dir.GetFiles("*.mp3"); 
InBlock.gif            number.Text
=mp3files.Length.ToString(); 
InBlock.gif            showfiles.Enabled
=false;//下面输出目录下的mp3文件 
InBlock.gif
            foreach (FileInfo  str in mp3files) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{                 
InBlock.gif                    show.Text
=show.Text+str+"\n"
InBlock.gif                                 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            move.Enabled
=true
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void number_Click(object sender, System.EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif         
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
private void move_Click(object sender, System.EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    string startpath; 
InBlock.gif            
int n; 
InBlock.gif            n
=0
InBlock.gif            l.Text
="已移动文件"
InBlock.gif            number.Text
=n.ToString(); 
InBlock.gif            startpath
=Application.StartupPath.ToString(); 
InBlock.gif            show.Text
=""
InBlock.gif            show.ReadOnly
=true
InBlock.gif            DirectoryInfo dir 
= new DirectoryInfo(startpath);//注册类 
InBlock.gif
            FileInfo[] mp3files = dir.GetFiles("*.mp3");//获取所有的mp3文件 
InBlock.gif
            number.Text=mp3files.Length.ToString();//mp3文件总数 
InBlock.gif
            showfiles.Enabled=false
InBlock.gif            
foreach (FileInfo  str in mp3files)//函数通过判断每个文件来分类 
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{    string files; 
InBlock.gif                 
InBlock.gif                files
=str.ToString().Substring(0,3)+"000";//获取文件名的前三个字符,然后加上三个0组成一个目录名 
InBlock.gif
                if(!Directory.Exists(startpath+"\\"+files))//判断前面的目录是否已经有了,如果没有再次生成目录 
ExpandedSubBlockStart.gifContractedSubBlock.gif
                dot.gif
InBlock.gif                    dir.CreateSubdirectory(files); 
InBlock.gif                     
ExpandedSubBlockEnd.gif                }
 
InBlock.gif                
if(!File.Exists(startpath+"\\"+files+"\\"+str))//判断文件时候有了,如果没有就移动文件 
ExpandedSubBlockStart.gifContractedSubBlock.gif
                dot.gif
InBlock.gif                    str.MoveTo(startpath
+"\\"+files+"\\"+str); 
InBlock.gif                show.Text
=show.Text+str+"---->"+files+"\n"
InBlock.gif                n
=n+1
ExpandedSubBlockEnd.gif                number.Text
=n.ToString();}
 
InBlock.gif                 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }
 
ExpandedBlockEnd.gif}
posted on 2006-02-03 14:22 Aween's Blog 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/aween/archive/2006/02/03/325003.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值