Link to home
Start Free TrialLog in
Avatar of Baub Eis
Baub EisFlag for United States of America

asked on

How to rename multiple files in multiple directories

I have directory structure similar to this

/images/widgets/widgetXXXXXX/xxxxx-LFS.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/11111/11111-LFS.pdf
would get changed to /images/widgets/widget/11111/11111-RENAME.pdf

/images/widgets/widget/22222/22222-LFS.pdf
would get changed to /images/widgets/widget/22222/22222-RENAME.pdf

/images/widgets/widget/33333/33333-LFS.pdf
would get changed to /images/widgets/widget/33333/33333-RENAME.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?
Avatar of Bill Prew
Bill Prew

Is there just one renaming pattern for all the files, in your example it was *-LFS to *-RENAME.  Or do have a bunch of those mappings that all have to be done?


»bp
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.

@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"
    )
)

Open in new window


»bp
Alternatively you  could try using Felxible Renamer -  https://download.cnet.com/Flexible-Renamer/3000-2248_4-28799.html
ASKER CERTIFIED SOLUTION
Avatar of Eirman
Eirman
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

User generated image

»bp