查找一个文件夹中的所有文件 [英] Find all files in a folder
本文介绍了查找一个文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待创造发现我的桌面上某一类型的所有文件,并将它们放到特定的文件夹的程序,例如,我会的所有文件以txt到文本文件夹中。
I am looking to create a program that finds all files of a certain type on my desktop and places them into specific folders, for example, I would have all files with .txt into the Text folder.
任何想法的最好办法是做到这一点?谢谢
Any ideas what the best way would be to accomplish this? Thanks.
我已经试过这样:
string startPath = @"%userprofile%/Desktop";
string[] oDirectories = Directory.GetDirectories(startPath, "");
Console.WriteLine(oDirectories.Length.ToString());
foreach (string oCurrent in oDirectories)
Console.WriteLine(oCurrent);
Console.ReadLine();
这是不是成功地找到的所有文件。
It was not successful in finding all of the files.
推荐答案
很多这些问题的答案将不实际工作中,尝试过他们自己。给这个一去:
A lot of these answers won't actually work, having tried them myself. Give this a go:
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
DirectoryInfo d = new DirectoryInfo(filepath);
foreach (var file in d.GetFiles("*.txt"))
{
Directory.Move(file.FullName, filepath + "\\TextFiles\\" + file.Name);
}
这将桌面上的所有.txt文件移动到文件夹 TEXTFILES
。
这篇关于查找一个文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文