Computing.Net > Forums > Disk Operating System > Batch file to rename multiple dir's

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file to rename multiple dir's

Reply to Message Icon

Name: Matt
Date: December 15, 2003 at 18:43:30 Pacific
OS: Win2000
CPU/Ram: 1.8G 512MB
Comment:

I want to change all the folder names in a directory so that they all start with the same 3 digit number. For Example, current folder names are 12345, 23456, 34567. I want to change them to 18045, 18056, 18067, etc. If they were files, I could use ren ???*.* 180*.*. Does anyone know of a similar command for the folders? Thanks for the help.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: December 16, 2003 at 01:08:01 Pacific
Reply:

The following batch performs what you need

@Echo Off

:: XRDIR.BAT Syntax: XRDir Folder_Name String
:: XRDir C:\MyFolder 180

Set Fld=%1
Set Str=%2

For /F %%a in ('Dir /B /AD-H %1') Do Call :REN %%a
GoTo :EOF

:REN
Set RDir=%*
Set RDir=%Str%%RDir:~3%
Echo Move "%Fld%\%*" "%Fld%\%RDir%"
GoTo :EOF

Type "XRDir Folder String" where Folder is the directory storing the subfolders to be renamed and String the three characyers to be replaced at the beginninig of folder's name
(blanks not allowed in folder's name).

Activate the script removing the Echo in front of Move command; do it only when sure it works fine.


0
Reply to Message Icon

Related Posts

See More


java interpreter for dos?... Backing up My Documents i...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch file to rename multiple dir's

a batch file to rename certain files www.computing.net/answers/dos/a-batch-file-to-rename-certain-files/10372.html

batch file to rename a file www.computing.net/answers/dos/batch-file-to-rename-a-file/8524.html

batch file to get subset of dir? www.computing.net/answers/dos/batch-file-to-get-subset-of-dir/15350.html