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