The following command only changes the name of the files but not the folders.
for %a in (*) do ren "%a" "00_%a"
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityThe following command only changes the name of the files but not the folders.
for %a in (*) do ren "%a" "00_%a"
for %a in (*) do ren "%a" "00_%a"
Notes:
for
as above is not advised.Use the following in a cmd
shell:
for /f "tokens=*" %a in ('dir /b') do ren "%a" "00_%a"
In a batch file (replace %
with %%
):
for /f "tokens=*" %%a in ('dir /b') do ren "%%a" "00_%%a"
Note:
It is critical that you use
FOR /F
and not the simpleFOR
.The
FOR /F
gathers the entire result of theDIR
command before it begins iterating, whereas the simpleFOR
begins iterating after the internal buffer is full, which adds a risk of renaming the same file multiple times.
as advised by dbenham in his answer to add "text" to end of multiple filenames:
To perform this For loop on folders (directories) instead of files, simply include the /D
switch.
for /D %a in (*) do ren "%a" "00_%a"
From for /?
:
FOR /D %variable IN (set) DO command [command-parameters]
If set contains wildcards, then specifies to match against directory names instead of file names.
ren
does work on folders. The limitation is that "you cannot specify a different drive or path for the Target.
– DavidPostill♦
Jan 18 '16 at 17:40
Ren
.
– Ƭᴇcʜιᴇ007
Jan 18 '16 at 17:40
for /d
may also have the problem of trying to process values multiple times (also see my answer).
– DavidPostill♦
Jan 18 '16 at 17:42