Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET4
Anyone have working code to move specified directory and its sub-folders + files from one volume to another on the same server? Need something that works right and is effecient. Thank you in advance.
Posted 3-Oct-12 7:58am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This isn't hard. Why don't you write it.
All you have to do is have a specified source root and a destination root.
Then iterate through all the directories in the source root and create/copy all the files and directories in each to the destination root.
You can check out this thread which has a couple of potential solutions for you: Clicky[^]
Member 8714829 at 3-Oct-12 14:09pm
I have actually done a few sample code but I wonder if there is a way to *move* a directory with its sub-folders and files using one call instead of having to drill douwn folder by folder....
If there is no such command then I am guessing the only way is to dril down to every folder, get its files, copy them then delete such folder and move on to the next folder...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There isn't a "nice" way - Directory.Move can't work across volumes since it just (effectively) re-writes the locations instead of moving any data.
Recursive File.Copy operations are one solution, but there is a "cheat".
Add a reference to Microsoft.VisualBasic, then this will work:
new Microsoft.VisualBasic.Devices.Computer().FileSystem.CopyDirectory(sourceDir, outputDir);
Nasty - but effective. You can then delete the source when completed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100