17

The following command only changes the name of the files but not the folders.

for %a in (*) do ren "%a" "00_%a"

| improve this question | |
18

The following command only changes the name of the files but not the folders.

for %a in (*) do ren "%a" "00_%a"

Notes:

  • Using for as above is not advised.
  • There is a possibility that files can be renamed multiple times.
  • See below for the reason why.

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 simple FOR.

The FOR /F gathers the entire result of the DIR command before it begins iterating, whereas the simple FOR 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:


Further Reading

| improve this answer | |
0

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.
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.