How to bulk add folder name to file name?

前端 未结 2 1154
自闭症患者
自闭症患者 2021-01-26 11:32

I have a folder struktur like this:

/1/1/master.jpg
/1/2/master.jpg
/1/3/master.jpg
/2/1/master.jpg
/2/2/master.jpg
/2/3/master.jpg
...

相关标签:
2条回答
  • 2021-01-26 12:01
    @echo off
    setlocal EnableDelayedExpansion
    cd C:\Parent\Folder\OfFirstNumberedFolders
    for /F "delims=" %%a in ('dir /B /S /A-D master.jpg') do (
       set "fullName=%%a"
       for /F "tokens=1-3 delims=\" %%b in ("!fullName:%CD%=!") do (
          ECHO ren "%%a" "%%b_%%c_%%d"
       )
    )
    
    0 讨论(0)
  • 2021-01-26 12:03

    Try this in Windows. Remove the echo to make it actually perform the rename.

    @echo off
    for /f "delims=" %%z in ('dir "master.jpg" /b /s /a-d ') do (
    for %%a in ("%%~dpz%\.") do (
    for %%b in ("%%~dpa\.") do (
    echo ren "%%z" "%%~nxb_%%~nxa_%%~nxz"
    )
    )
    )
    pause
    
    0 讨论(0)
提交回复
热议问题