I'm trying to do some renaming but recursively, below is where I am and I am a bit stuck. I added a remark where I think I'm wrong.
@echo off
setlocal enableextensions enabledelayedexpansion
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""
for /f "usebackq delims=" %%i in (`powershell %psCommand%`) do set "rootfolder=%%i"
@echo on
cd %rootfolder%
for /r "%rootfolder%\" %%a in (*) do (
set "folder=%%~dpa"
cd %%~dpa
for %%i in ("!folder!") do (
set parent=%%~ni
)
:: for %%i in ("!folder!") do (set parent=%%~ni)
:: that part returns me parent=
:: i would like it to be for example if folder is d:\test\test1
:: parent = test1
set /a count=10000
for /F "eol=| delims=" %%f in ('dir /B /A:-D-H-S /O:N "*.tif"') do (
set /a count =1
set fileName=!parent!_!count:~-4!%%~xf
rename "%%f" "!fileName!"
)
)
exit /b
CodePudding user response:
Hello,
posting an answer to my question, i managed to find a solution, you can see it below but i'm sure that right now the people like you who knows what they're doing have bleeding eyes.
so if you want to help me making that script look nicer, you're very welcome.
@echo off
setlocal enableextensions enabledelayedexpansion
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""
for /f "usebackq delims=" %%i in (`powershell %psCommand%`) do set "rootfolder=%%i"
cd %rootfolder%
for /r "%rootfolder%" %%a in (*) do (
set Fdir=%%~dpa
call :001 "%%~a"
)
:001
cd