Search code examples
windowssubdirectorybatch-rename

How to Add prefix to all file in current folder and subfolder using batch file


I am trying to add prefix to all files in current folder and it's subfolders and i made the following batch file

setlocal enabledelayedexpansion
for %%j in (*) do (
set filename=%%j
rename !filename! [nilesh.uk.to]-!filename!
)

it working for current directory only but i want to add prefix to all files in current folder as well as subdirectory please help me to solve this problem


Solution

  • Run this from another folder, and the pushd is used otherwise the batch file will be renamed too. Change c:\mainfolder to your main folder name

    @echo off
    pushd "c:\mainfolder\"
    for /r %%j in (*) do (
       rename "%%j" "[nilesh.uk.to]-%%~nxj"
    )
    popd