Assume I have this structure:
d:/
-- /alpha/
-- /beta/
-- /gamma/
-- /delta/
I'm trying to execute a batch file that goes through those folders (but not through sub-folders within them).
How do I get this result using a FOR LOOP (assuming I don't know the name and quantity of the folders):
ren alpha alpha1
ren beta beta1
ren gamma gamma1
ren delta delta1
To use for in a batch file, use the following syntax: for {%%|%}<variable> in (<set>) do <command> [<commandlineoptions>] To display the contents of all the files in the current directory that have the extension .doc or .txt by using the replaceable variable %f, type: for %f in (*.doc *.txt) do type %f.
Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory.
For loop (default) of Batch language is used to iterate over a list of files. Example: copy some files into a directory (Note: the files to be copied into the target directory need to be in the same disk drive).
This is all you should need:
for /D %i in (*) do rename "%i" "%i1"
The /D performs the command against the directory names, as per the help, which can be obtained using the command for /?
If Command Extensions are enabled, the following additional forms of the FOR command are supported:
FOR /D %variable IN (set) DO command [command-parameters]
If set contains wildcards, then specifies to match against directory names instead of file names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With