Click here to Skip to main content
Rate this: bad
good
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
good
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[^]
  Permalink  
v2
Comments
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
good
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 Tadit Dash 215
2 Sergey Alexandrovich Kryukov 190
3 OriginalGriff 183
4 Peter Leow 130
0 Sergey Alexandrovich Kryukov 9,325
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


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