Saturday, July 17, 2010

Move File / Folder

To move a file or a folder using C# we need the function Move() of the classes System.IO.File or System.IO.Directory:

System.IO.File.Move("C:\\sourcefile.txt""C:\\testfolder\\targetfile.txt");
System.IO.Directory.Move("C:\\sourcefolder""C:\\testfolder\\targetfolder");

In both variants the first parameter represents the path to the sourcefile / sourcefolder, the second to the targetfile / targetfolder.
The path has to be valid, otherwise the function throws an exception.

No comments:

Post a Comment