Script package for file name prefix

I am trying to rename files in a batch script as follows:

rename %FOLDER%\* 1-* 

but when you run the script, it overwrites the first two characters of the original names with the prefix "1-" instead of adding it to the beginning of the file names. How can I get around this?

+4
source share
2 answers

Rename will simply rename the file, you will need to call the file name as a variable after the prefix. The following shows how it works.

 cd %folder% for %%a in (*) do rename "%%a" "1-%%a" 
+7
source

try this as a starting point

 @echo off for %%a in (%folder%\*) do ( echo ren "%%~fa" "1-%%~nxa" ) 
+1
source

Source: https://habr.com/ru/post/1387451/


All Articles