Add to folder name

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
I have a directory with a bunch of sub folders. I need to add a number and underscore to the main folder and all sub folders.

Example

Subfolder
Atmos_Energy

I need it to say
05_Atmos_Energy

There will be 500 subfolders

How would I have a form that can name all the subfolders at once?

Thanks
 
String cannot be of zero length. Parameter name: oldValue
That means that strPrefix = "", it needs to have a value like "01_".

Argument 'newName' must be a name, and not a relative or absolute path: 'C:\prioritytest\\1_77_prioritytest_01'. Parameter name: newName
I guess there was an issue with JohnH's code, instead of "newname = prefixNumber & IO.Path.GetFileName(direct)" in the renameFolders, use "newname = prefixNumber & IO.Path.GetDirectoryName(direct)"
 
Thanks Joshdbr -


still not working.

I am doing this because we have a big job at work, however, I will just have to tell everyone that if they rename the wrong directory they will just have to rename each folder (about 300 - 500 of them) themselves.

I was just trying to fix a problem before it occured, however, I am spending too much of my time, and yours.

Thanks for all your help and you desever mucho kudos.

thanks

daveofgv
 
I guess there was an issue with JohnH's code, instead of "newname = prefixNumber & IO.Path.GetFileName(direct)" in the renameFolders, use "newname = prefixNumber & IO.Path.GetDirectoryName(direct)"
No, there wasn't an issue with my code, and you can't use GetDirectoryName (look it up!).

RenameDirectory takes parameters in this form ("c:\folder\name", "newname"), and the result after rename is this path: c:\folder\newname.
 
So what is GetDirectoryName for?
 
Thanks :).
 
So the Path.GetDirectoryName method simply returns the directory path of the specified file or the next directory up if a directory is specified. It just gets the directory name :). I'm not sure who I confuse more, myself or the person I am trying to help!
 
Back
Top