Change extension of specific filetype on current folder and subdirectories with .bat

StackOverflow https://stackoverflow.com/questions/20148923

  •  03-08-2022
  •  | 
  •  

문제

I would like to rename all the .log as .ok from a particular folder and subdirectories

도움이 되었습니까?

해결책

The following will usually work just fine:

@echo off
for /r "PathToYourFolderHere" %%F in (.) do ren "%%F\*.log" *.ok

But the above can have problems if short file names are enabled on your drive and you have extensions longer than 3 characters. It will also rename files like name.log2 because the short name will have an extension of .log.

The following will only rename true .log files:

@echo off
for /f "eol=: delims=" %%F in (
  '"dir /b /s /a-d PathToYourFolder\*.log|findstr /lie .log"'
) do ren "%%F" *.ok

Note: The rules for how RENAME treats wildcards can be found at How does the Windows RENAME command interpret wildcards?

다른 팁

run a .bat file from the folder containing:

for /R %%x in (*.log) do rename "%%x" "%%~nx.ok"
  • /R for recursive
  • %%~nx for the filename without extension
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top