Renaming issue

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
windexian
Posts: 1
Joined: 19 Mar 2014 11:24

Renaming issue

#1 Post by windexian » 19 Mar 2014 11:44

Hi all, first time poster here... the short version is I have a folder auto-downloaded to a server each week. The original folder's location & name: "Y:\MrMaster\House of Hair (3 Hour) AIRS SUNDAY ONLY 03.23.14 5 for KSNQ-FM only"

I want to rename the folder using a batch file. New name needs to be "Y:\MrMaster\HOUSE" (sans quotes of course)

Two issues I'm experiencing. 1) Can't accomplish the rename even one time, and 2) The date on the auto-downloaded folder changes each week. Everything else on the folder's name is the same.

The server is the Y drive.

The following code does not accomplish this, and I'm wondering what I need to change:

cd y:\mrmaster

ren y:\mrmaster\*house* HOUSE

Any thoughts?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Renaming issue

#2 Post by dbenham » 19 Mar 2014 21:24

Wildcards cannot be used when renaming folders. They work fine for file names, but never for folder names. See http://superuser.com/q/475874/109090 for rules on how Windows REN command interprets wildcards.

I suggest the following for renaming your folder (assuming there is only one folder that matches the *house* mask).
Edit: added the critical /D option, and also added the path

Code: Select all

for /d %%F in (y:\mrmaster\*house*) do ren "%%F" HOUSE


Dave Benham

Post Reply