Search code examples
batch-filefile-ioprefix

Batch script to prefix file names


I am trying to rename files in a batch script like this:

rename %FOLDER%\* 1-*

but when I 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 work around this?


Solution

  • Rename will just rename the file, you would need to call the file name as a variable after the prefix. The below is what ended up working.

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