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.
I have tried this:
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.
Type dir /A:D. /B > FolderList. txt and press Enter to generate a top-level folder list. When the list is complete, a new, blank prompt with a flashing cursor will appear.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With