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

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

  •  03-08-2022
  •  | 
  •  

Domanda

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

È stato utile?

Soluzione

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?

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top