Baub Eis
asked on
How to rename multiple files in multiple directories
I have directory structure similar to this
/images/widgets/widgetXXXX XX/xxxxx-L FS.pdf
xxxxx is a unique number to each folder/listing
Its on a windows server, I need to change all of the files to something else, but do it recursively, so that it will do it in all the folders within the /images/ folder
So something like this
/images/widgets/widget/111 11/11111-L FS.pdf
would get changed to /images/widgets/widget/111 11/11111-R ENAME.pdf
/images/widgets/widget/222 22/22222-L FS.pdf
would get changed to /images/widgets/widget/222 22/22222-R ENAME.pdf
/images/widgets/widget/333 33/33333-L FS.pdf
would get changed to /images/widgets/widget/333 33/33333-R ENAME.pdf
and so on. I know how to do the ren command random characters etc *-LFS.PDF
But not sure how to tell it to do all the directorys?
/images/widgets/widgetXXXX
xxxxx is a unique number to each folder/listing
Its on a windows server, I need to change all of the files to something else, but do it recursively, so that it will do it in all the folders within the /images/ folder
So something like this
/images/widgets/widget/111
would get changed to /images/widgets/widget/111
/images/widgets/widget/222
would get changed to /images/widgets/widget/222
/images/widgets/widget/333
would get changed to /images/widgets/widget/333
and so on. I know how to do the ren command random characters etc *-LFS.PDF
But not sure how to tell it to do all the directorys?
If you just need to do that single pattern here is a BAT script approach to that. Adjust the BaseDir as needed at the top and adjust the -LFS and -RENAME as needed.
»bp
@echo off
setlocal EnableDelayedExpansion
rem Set base directory to process
set BaseDir=B:\EE\EE29136096\images\widgets\widget
rem Itterate through folders in base dir
for /d %%D in ("%BaseDir%\*") do (
rem Itterate each matching file in this folder
for %%F in ("%%~D\*-LFS.pdf") do (
rem Get just base name of this file (no extension)
set NewName=%%~nF
rem Replace part of name we want to rename
set NewName=!NewName:-LFS=-RENAME!
rem Do the rename
ren "%%F" "!NewName!%%~xF"
)
)
»bp
Alternatively you could try using Felxible Renamer - https://download.cnet.com/Flexible-Renamer/3000-2248_4-28799.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just for future reference, another great tool I use for "interesting" renames, very powerful, and free!
Advanced Renamer - Free and fast batch rename utility for files and folders
»bp
Advanced Renamer - Free and fast batch rename utility for files and folders
»bp
»bp