首先在c:/file目录下建立两个文件夹bmpfile和giffile,在c:/file下放几张图片
private void fileExtension()

...{
System.String fPath = @"C: ile";
DirectoryInfo dirInfo = new DirectoryInfo(fPath);
FileInfo[] fi = dirInfo.GetFiles();
//get the num of the file
System.Int32 fileNum = fi.Length;
MessageBox.Show("the num of the file is " + fileNum);
foreach (FileInfo fInfo in fi)

...{
switch (fInfo.Extension)

...{
case ".bmp":
//最后一个后有空格
fInfo.MoveTo(@"C: ilempfile " + fInfo.Name);
break;
case ".gif":
fInfo.MoveTo(@"C: ilegiffile " + fInfo.Name);
break;
default:
break;
}
}
}
private void fileExtension()
...{
System.String fPath = @"C: ile";
DirectoryInfo dirInfo = new DirectoryInfo(fPath);
FileInfo[] fi = dirInfo.GetFiles();
//get the num of the file
System.Int32 fileNum = fi.Length;
MessageBox.Show("the num of the file is " + fileNum);
foreach (FileInfo fInfo in fi)
...{
switch (fInfo.Extension)
...{
case ".bmp":
//最后一个后有空格
fInfo.MoveTo(@"C: ilempfile " + fInfo.Name);
break;
case ".gif":
fInfo.MoveTo(@"C: ilegiffile " + fInfo.Name);
break;
default:
break;
}
}
}
本文介绍了一种使用C#编程语言实现的文件分类方法,该方法能够自动将不同类型的文件(如.bmp和.gif图片)移动到相应的文件夹中。通过获取指定路径下的所有文件并检查其扩展名来实现文件的自动分类。
923

被折叠的 条评论
为什么被折叠?



