.net - Copy the entire contents of a directory in C# -
i want copy entire contents of directory 1 location in c#.
there doesn't appear way using system.io
classes without lots of recursion.
there method in vb can use if add reference microsoft.visualbasic
:
new microsoft.visualbasic.devices.computer(). filesystem.copydirectory( sourcefolder, outputfolder );
this seems rather ugly hack. there better way?
much easier
//now create of directories foreach (string dirpath in directory.getdirectories(sourcepath, "*", searchoption.alldirectories)) directory.createdirectory(dirpath.replace(sourcepath, destinationpath)); //copy files & replaces files same name foreach (string newpath in directory.getfiles(sourcepath, "*.*", searchoption.alldirectories)) file.copy(newpath, newpath.replace(sourcepath, destinationpath), true);
Comments
Post a Comment