0

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

Charles
  • 50,943
  • 13
  • 104
  • 142
baptme
  • 10,062
  • 3
  • 52
  • 57

2 Answers2

3

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?

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
1

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
baptme
  • 10,062
  • 3
  • 52
  • 57
  • 1
    +1, This will work in most cases. But it will also rename files like `name.logX` if short file names are enabled. It will always work if short names are disabled, or if no extensions longer than 3 chars exist that begin with `.log`. – dbenham Nov 22 '13 at 16:07