trevor1940
asked on
DOS: Rename files recursivly
Hi
I need to rename some files
This works if I cd to the directory first
How do I write a simple bat file that takes the parent folder as a parameter and recursively renames the files skipping over if the files exist
so if a folder had both MyCat.jpeg and mycat.jpg it won't over right mycat.jpg (Windows file names are not case sensitive) and won't prompt
I need to rename some files
This works if I cd to the directory first
cd \s z:\Path\with\files\in
ren *.jpeg *.jpg
How do I write a simple bat file that takes the parent folder as a parameter and recursively renames the files skipping over if the files exist
so if a folder had both MyCat.jpeg and mycat.jpg it won't over right mycat.jpg (Windows file names are not case sensitive) and won't prompt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes to passing the base folder path in as a parm, that looks okay, except don't add quotes around the %~1.
No, %%~dpnF.jpg is not using wildcards. The %%F is the loop variable from the FOR statement, it will contain the full path of the current file as the FOR itterates. %%dpnF uses modifiers dpn to get just the drive, path and base file name of the file, basically removing the .jpeg extension. Then %%~dpnF.jpg concatenates .jpg at the end so we can determine if there is already a JPG file there with the same name.
»bp
No, %%~dpnF.jpg is not using wildcards. The %%F is the loop variable from the FOR statement, it will contain the full path of the current file as the FOR itterates. %%dpnF uses modifiers dpn to get just the drive, path and base file name of the file, basically removing the .jpeg extension. Then %%~dpnF.jpg concatenates .jpg at the end so we can determine if there is already a JPG file there with the same name.
»bp
ASKER
Thanx Bill for the answer and follow up explanation
Welcome, glad that was helpful.
»bp
»bp
ASKER
assuming I've named the file
RenJPG.bat
how do run this
Open in new window
I'm guessing something like this
@echo off
setlocal
set BaseDir="%~1"
for /r "%BaseDir%" %%F in ("*.jpeg") do (
if not exist "%%~dpnF.jpg" (
ren "%%~F" "*.jpg"
)
)
Is the a wildcard?
"%%~dpnF.jpg"