I am trying to write a batch script to rename multiple folders.
I would like to do something like below:
Rename all folders under the “Workspace” folder by appending my name in the end of the folder names
For example, rename:
Workspace/RiskFolder
Workspace/PNLFolder
to:
Workspace/RiskFolder_myname
Workspace/PNLFolder_myname
Is this possible?
You could use for to loop through each directory and rename it like so:
I tested this on Windows 7, but it should work at least as far back as with Windows XP.
What that does is this: for each directory in the path (within parenthesis), assign the directory name to the variable
%%f, then rename the directory%%fto the name in the format you want (with your name attached).%%fholds the full pathname, which is fine for the first argument to therenamecommand, but for the second argument, we only want the filename+extension, thus the ~nx modifier prepended to our variable name.By the way, when using this
forloop on the command line (rather than part of a batch file) you only want to use one % instead of %% for your variable name. E.g.for %f in...instead of above.See the following references from Microsoft for more details: