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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invert file naming 1

Status
Not open for further replies.

Aurillius

Programmer
Jun 3, 2004
60
CA
Hi,
I have a series of files that need to be renamed so that the low numbers are the highest and the high numbers are the lowest.

Change to something like:

K8966-001.jpg to K8966-030
K8966-002.jpg to K8966-029
K8966-003.jpg to K8966-028
K8966-004.jpg to K8966-027
K8966-005.jpg to K8966-026
K8966-006.jpg to K8966-025
K8966-007.jpg to K8966-024

I've tried a few renaming utilities but none of them worked, (or maybe I'm looking in the wrong places).

Aurillius
 
I use Excel to do jobs like this. I use a DOS command to save a directory listing to a text file - something like dir/b > filelist.txt will do nicely.

I import that into excel and use a few judicious formulas to generate suitable dos command lines in a new column. I am sure as a programmer you can soon work out how! I then copy that column to a new worksheet (data only!) and save it as a .prn file. Rename it to .bat and double click on it! Works a treat!

Hint - your final column reads something like this.

"rename " & char(34) & (old name) & char(34) & " " & char(34) & (formula for new name) & char(34)
 
I understand the logic in concatenating the cells and pasting into a notepad file and renaming to a .bat file. The commands are not working when I run the batch file though. I get the following error:
' r' is not recognized as an internal or external command, operable program or batch file

What is the exact syntax of the line?


 
You have to save the sheet as a .prn (Formatted text, space delimited) file. This ensures that the double quote character '"' is saved in the file as such and not translated. It also ensures you get no tab characters, only spaces!

There can be only one column in that sheet
Excel will only save that sheet (which is fine)
There can be no formulas in that sheet.

Hence you work on one sheet and copy/paste the final result column to another sheet using paste special - values only!

The syntax 'DOS' is expecting is

rename "filea.xyz" "fileb.xyz"

taking your example above!

rename "K8966-001.jpg" "K8966-030.jpg"
rename "K8966-002.jpg" "K8966-029.jpg"


N.B. using the quotes avoids any long filename issues!

if you still can't get it to work - post a bit of your excel generated batch file here so I can see it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top