Reputation: 2615
In my "C:\image\Test_Directory\" i have various folders named {hello1, hello2, hello3, hello4} etc... I wanted to remove the word hello in my folders under my "C:\image\Test_Directory\" so the folders would read {1, 2, 3, 4} etc... I searched online on how to do this but i had no luck.
Example Issue:
GOAL:
Upvotes: 1
Views: 230
Reputation: 301
Use RenameDirectory() function Try this :
Dim dir As DirectoryInfo = New DirectoryInfo("C:\image\Test_Directory")
Dim folders As DirectoryInfo() = dir.GetDirectories()
For Each folder As DirectoryInfo In folders
My.Computer.FileSystem.RenameDirectory(folder.FullName, folder.Name.Replace("Hello", ""))
Next
Upvotes: 1
Reputation: 19496
You'd use Directory.Move()
to rename the folders:
foreach (var dirName in Directory.GetDirectories(@"C:\image\Test_Directory"))
{
string newName = dirName.Replace("Hello", "");
Directory.Move(dirName, newName);
}
Upvotes: 2