![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Renaming Multiple files | dhiren_shah | UNIX for Dummies Questions & Answers | 2 | 09-12-2008 02:23 AM |
| Renaming multiple files | amit4g | Shell Programming and Scripting | 2 | 07-14-2008 09:36 AM |
| Renaming of multiple filenames | shashi_kiran_v | UNIX for Dummies Questions & Answers | 7 | 07-05-2005 09:33 AM |
| Renaming multiple files | rmayur | UNIX for Dummies Questions & Answers | 6 | 02-26-2004 04:40 AM |
| Renaming multiple files | jxh461 | Shell Programming and Scripting | 4 | 04-01-2003 07:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Multiple file renaming
Hi All,
I have a number of files in a directory that I would like to rename - I am quite aware that you can use the mv command to rename the files - I would like to rename them automatically from the command line instead of having to do them singly. I have searched the forum pertaining to renaming multiple files but they do not seem to do what I want. What I would like to do is change the name of the file to whatever name I want for example Cuba1.JPG Cuba2.JPG etc etc. The files which I want to rename is shown below. IMAG0001.JPG IMAG0002.JPG.ext2.ext2.ext2 IMAG0003.JPG.ext2.ext2.ext2 IMAG0005.JPG.ext2.ext2.ext2 IMAG0006.JPG.ext2.ext2.ext2 Any help is appreciated. Rgds. |
|
||||
|
if you have Python, you can use the script here
example usage Code:
# ls -1 IMAG0001.JPG IMAG0002.JPG.ext2.ext2.ext2 IMAG0003.JPG.ext2.ext2.ext2 IMAG0005.JPG.ext2.ext2.ext2 IMAG0006.JPG.ext2.ext2.ext2 ## filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG" -l -n "IMAG*" #remove -l to commit ==>>>> [ /home/IMAG0001.JPG ]==>[ /home/CUBA01.JPG ] ==>>>> [ /home/IMAG0002.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA02.JPG ] ==>>>> [ /home/IMAG0003.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA03.JPG ] ==>>>> [ /home/IMAG0005.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA04.JPG ] ==>>>> [ /home/IMAG0006.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA05.JPG ] # filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG" -n "IMAG*" /home/IMAG0001.JPG is renamed to /home/CUBA01.JPG /home/IMAG0002.JPG.ext2.ext2.ext2 is renamed to /home/CUBA02.JPG /home/IMAG0003.JPG.ext2.ext2.ext2 is renamed to /home/CUBA03.JPG /home/IMAG0005.JPG.ext2.ext2.ext2 is renamed to /home/CUBA04.JPG /home/IMAG0006.JPG.ext2.ext2.ext2 is renamed to /home/CUBA05.JPG # ls -1 CUBA01.JPG CUBA02.JPG CUBA03.JPG CUBA04.JPG CUBA05.JPG Last edited by ghostdog74; 10-07-2008 at 08:40 PM.. |
|
||||
|
Multiple file renaming
Quote:
I have tried t run it by copying the lines of code then pasting it in at the python prompt. When that happens I get the error >>> [ /Users/johndoe/Desktop/Test/Picturefolder/IMAG0001.JPG ]==>[ /Users/johndoe/Desktop/Test/Picturefolder/CUBA01.JPG ] File "<stdin>", line 1 [ /Users/johndoe/Desktop/Test/Picturefolder/IMAG0001.JPG ]==>[ /Users/johndoe/Desktop/Test/Picturefolder/CUBA01.JPG ] ^ SyntaxError: invalid syntax >>> What am I doing wrong here? Thanks & Rgds. |
|
||||
|
Looks like you copy+pasted the example result rather than the actual code. The script you want is available from the link behind the text "here" in ghostdog74's posting; visit the web page and you'll find a piece of code which you can "save as" filerenamer.py -- it begins with the following
Code:
#!/usr/bin/env python import sys,os,getopt,glob,string,re,operator,fnmatch,time Save into a file, chmod +x the file, and go. |
|
||||
|
save the script as filerenamer.py and make sure its executable, then you can either use ./filerenamer.py ... or python filerenamer.py <options>
I have got the script copied to one of the directories in my PATH variable, that's why i can use just "filerenamer.py" |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|