Find all files in a folder

后端 未结 3 1382
别那么骄傲
别那么骄傲 2020-12-01 10:12

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 in

3条回答
  •  青春惊慌失措
    2020-12-01 10:48

    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);
    }
    

    It will move all .txt files on the desktop to the folder TextFiles.

提交回复
热议问题