I'm updating an old winforms app which moves files to new locations using regex and System.IO.File.Move
Under windows 7, the old app worked fine. If a folder didn't exist, File.Move would create it
System.IO.File.Move("c:\stuff\a.txt","c:\stuff\a\file.txt");
System.IO.File.Move("c:\stuff\b.txt","c:\stuff\b\file.txt");
System.IO.File.Move("c:\stuff\c.txt","c:\stuff\c\file.txt");
However, under Windows 8 it seems that I have to manually create each folder in the path first. I get an error if I try and move to a folder that doesn't exist yet. Anyone know a way around this? I'd rather not have to create each folder
NOTE: The new, updated app is on WPF rather than winforms. Not sure if that's relevant
Illustrious. Whenever you move a file within the same drive/partition, it physically remains on the same spot. Only its path is changed within the file system on the drive.
File. Move() doesn't support overwriting of an existing file. In fact, it will throw an IOException if a file with the same path as sourceDestFilename already exists.
You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop. Folder Tree: Right-click the file or folder you want, and from the menu that displays click Move or Copy.
Before you File.Move()
you could do:
new System.IO.FileInfo("c:\\stuff\\a\\file.txt").Directory.Create();
The above will create the "stuff" and "a" folders if they don't exist.
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