Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Rename command 1

Status
Not open for further replies.

HRingman

Technical User
Jul 15, 2010
8
US
Can someone please explain to me how to use the rename command to replace part of a file name?

We have a lot of pdf files named something like "12 34 232 0100 0000 XX – APPROVED". When there is a new revision, we have to changed the pdf name from approved to superseded, so it should say "12 34 232 0100 0000 XX – SUPERSEDED". When there are a lot of files that need to be changed from approved to superseded at once, I thought the rename command could help me do it quickly, but it's not working for me.

I went to the command window, and directed it to the folder I had my files in. When I put “ren *APPROVED.pdf *SUPERSEDED.pdf” then the name changed from “12 34 232 0100 0000 XX – APPROVED” to “12 34 232 0100 0000 XX – APPROVED.pdfSUPERSEDED”. Same thing happened when I put “ren *APPROVED*.pdf *SUPERSEDED*.pdf”.

Since that wasn't working, I thought I would test the command and try to change the part of the file name 232 to ABC, so I put “ren *232*.pdf *ABC*.pdf”, and the names go from “12 34 232 0100 0000 XX – APPROVED” to “12 34 232 0100 0000 XX – ABCroved”, so now I really don't know what's going on.

If someone could explain what I'm doing wrong and how to do it right I'd appreciate it.
 
you'd need a batch file, which reads the filename, then dropping the APPROVED part, then adding the SUPERSEDED portion, and then renaming it from old to new...

or search for a GUI based renaming app that does that and more...

e.g.

1-4a rename



Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"
 
Go to Start|Control Panel|Folder Options|View Tab|Uncheck Hide extensions for known file types
 
Are your filenames all the same length? If so, you could use the set command
Code:
for /f %f in (*APPROVED.pdf) do (
set xx=%f:1,10%
ren "%f" "%xx% - SUPERSEDED.pdf"
)
where 10 is the number of characters before the - APPROVED. Have a play and see what you get. You could always use echo instead of ren to see what it is going to do first
 
Thanks for the advice y'all, but I still can't get it to work.

BadBigBen- That sounds like that would work for me, but I don't know that much about batch files, so I don't know how I would drop APPROVED and then add SUPERSEDED.

mlgmartin- The same thing happens whether I have the file extensions hidden or not. And I think for the rename command it's needed to put the file extensions, because if I put "ren *APPROVED *SUPERSEDED" then the command window says "The system cannot find the file specified."

xwb- The filenames are the same length. For the set command, do I just type what you put into the command prompt? When I typed that stuff that you show, it says "The system cannot find the file *APPROVED.pdf"

 
You cannot use an asterisk as anything but a suffix for the name or extension. CMD.EXE (like COMMAND.COM) ignores anthing following the asterisk (except the period, of course).

xwb's approch is the only one that might work in a simple batch program. I have in the past written a COBOL program that reads a list of file names and generates a batch file to explicitly rename each file according to the coded specifications. I imagine such a program could also be written in VB or any other full language.
 
Try this method.

ren ???????????????????????APPROVED.pdf ???????????????????????SUPERCEDED.pdf

just tested and this seems to work

The question mark is a wild card for any character and you also have to represent the spaces with a question mark. I counted 20 characters (including spaces) in your example.

 
jkl0 thank you! That worked! This is very exciting.

And thanks again to everyone else for your help.
 
The problem was the spaces in the file names. While valid names, they confuse most DOS based commands.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top