Moving Directories

  • Thread starter Thread starter Russ
  • Start date Start date
R

Russ

Hi,

What's the simplest .NET framework way of renaming part of a directory
structure?

For example I want to rename:-

C:\Level1\Level2\Level3\[several sub directories]

to

C:\Level1\Level2\NEWLevel3\[several sub directories]

Thanks
Russ
 
Use:

DirectoryInfo di = new DirectoryInfo("path");
di.MoveTo("");

Use MoveTo() with the new name.

sayed
 
Sayed,

I already tried that.

File/Directory already exists.

Russ

Sayed Hashimi said:
Use:

DirectoryInfo di = new DirectoryInfo("path");
di.MoveTo("");

Use MoveTo() with the new name.

sayed

"Russ" <[email protected]> wrote in message
Hi,

What's the simplest .NET framework way of renaming part of a directory
structure?

For example I want to rename:-

C:\Level1\Level2\Level3\[several sub directories]

to

C:\Level1\Level2\NEWLevel3\[several sub directories]

Thanks
Russ
 
Hi

Provided the directory tree is as below.
C:\LEVEL1
©¸©¤level2
©¸©¤level3
©À©¤level4
©¸©¤level5

and we wants to make the directory tree as below.
C:\LEVEL1
©À©¤level2
©¸©¤Newlevel2
©¸©¤level3
©À©¤level4
©¸©¤level5


We need to create the Newlevel2 first.
Here is the code.
Directory.CreateDirectory(@"c:\level1\Newlevel2");
Directory.Move(@"c:\level1\level2\level3",@"c:\level1\Newlevel2\level3");



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ok Peter,

Thanks for that. I thought I'd already tried that but it's working fine
now (duh).

Thanks again,
Russ
 
Back
Top