Rename Directory/Folder
-
Hello I am trying to rename a Direcotry/folder in windows My way to do it goes like this: private void RenameFolder(DirectoryInfo dir, string NewName) { FileInfo fl = new FileInfo(dir.FullName); fl.MoveTo(string.Concat(dir.Parent + "\\" + NewName)); } My question is if this is the best way to rename a directory/folder? Thanks QzRz
-
Hello I am trying to rename a Direcotry/folder in windows My way to do it goes like this: private void RenameFolder(DirectoryInfo dir, string NewName) { FileInfo fl = new FileInfo(dir.FullName); fl.MoveTo(string.Concat(dir.Parent + "\\" + NewName)); } My question is if this is the best way to rename a directory/folder? Thanks QzRz
Hi. You can also use
Directory.Move(string src,string dest)
Or evenDirectoryInfo.MoveTo()
So to use your existing code, this can be simplified to:private void RenameFolder(DirectoryInfo dir, string NewName)
{
dir.MoveTo(Path.Combine(dir.Parent.FullName,NewName));
}Graham -- modified at 17:12 Sunday 18th June, 2006
-
Hi. You can also use
Directory.Move(string src,string dest)
Or evenDirectoryInfo.MoveTo()
So to use your existing code, this can be simplified to:private void RenameFolder(DirectoryInfo dir, string NewName)
{
dir.MoveTo(Path.Combine(dir.Parent.FullName,NewName));
}Graham -- modified at 17:12 Sunday 18th June, 2006