Find all files in a folder

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.

Leave a Comment