views:

215

answers:

3

Let: Folder to rename c:\temp\Torename to: c:\temp\ToRename

Directory.Move does not work because the folder(:\temp\Torename) already exist.

I am looking for a solution that does not involve creating a temp folder. I have this solution in place: Move to a temp folder (unique name) eg c:\temp\TorenameTemp Move from temp folder to new folder. eg c:\temp\ToRename The problem is that my folder can get very big and move can take some time to execute. I like windows explorer solution in which user renames on the spot regardless of size.

thanks for yor time.

+2  A: 

Directory.Move doesn't scale with the directory size (unless you're copying to a different drive), so there's nothing wrong with calling it twice.

SLaks
+5  A: 
Directory.Move(@"C:\Temp\Dir1", @"C:\Temp\dir1_temp");
Directory.Move(@"C:\Temp\dir1_temp", @"C:\Temp\dir1");

The files won't be moved unless you are moving them to a different volume. If destination is on the same volume, only the name of directory will change.

LymanZerga
This solution will be used against a network drive.(\\server\MyShare\dir1)
mas_oz2k1
As long as the volume is the same, you will be fine.
LymanZerga
A: 

Directory.Move for directory File.Move for file

Cryeyes