Multiple file renaming


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Multiple file renaming
# 1  
Old 10-07-2008
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.
# 2  
Old 10-07-2008
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..
# 3  
Old 10-08-2008
Multiple file renaming

Quote:
Originally Posted by ghostdog74
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

Thanks for your reply - I have python running on my system and it's the 1st time I've used it to be honest. Needless to say I do not know anything about it. The script that you've written, can it be used on any flavour of UNIX - I am using Mac OS X, I'm not sure if that has anything to do with the output which I'm getting of whether I do not know how to run the actual script.

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.
# 4  
Old 10-08-2008
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

etc.

Save into a file, chmod +x the file, and go.
# 5  
Old 10-09-2008
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"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting file into multiple files and renaming them

Hi all, Newbie here. First of all, sorry if I made any mistakes while posting this question in terms of rules. Correct me if I am wrong. :b: I have a .dat file whose name is in the format of 20170311_abc_xyz.dat. The file consists of records whose first column consists of multiple dates in... (2 Replies)
Discussion started by: chanduris
2 Replies

2. Shell Programming and Scripting

Multiple File renaming with a twist

Hi I can do simple file renaming but this task is slightly more troublesome Ive got a guy that gives me multiple .pdf filles in a directory named something like 3412345.pdf 4565465.pdf 8534534.pdf And he also gives me a html file which is tabled with which shows the filenames above... (2 Replies)
Discussion started by: messiah1
2 Replies

3. Shell Programming and Scripting

Renaming file that has multiple numbers as filename

Hi I have a file with filename as "partition-setup-and-ipl.vtcmd.76217657132.9721536798" Now i need to move this file as "partition-setup-and-ipl.vtcmd.76217657132.9721536798_org" i tried with # ls | grep -E "partition-setup-and-ipl.vtcmd.+"... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

Renaming multiple files

I have 34 file in a directory that all have different names, however, they do have 1 pattern in commmon. They all have "-10-11-2010" date format in the name. I want to replace the date in the file name with a supplied date or maybe even the system date. I am sure I will be using awk or sed to... (9 Replies)
Discussion started by: Harleyrci
9 Replies

5. UNIX for Dummies Questions & Answers

Renaming multiple files

Hi, Can we rename multiples files using find or awk utility? Now I am doing it using for loop and getting the file name and in side the loop using the mv command. Like ine need t rename all txt files to doc file. For example a1.txt => a1.doc a2.txt => a2.doc a3.txt => a3.doc myfile.txt... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

6. Shell Programming and Scripting

renaming multiple files

I have to rename 100+ files at a time on the server & was trying to use a script for doing that. I have used ultra edit to create a file having current filename & new file name as below file234.txt | file956.txt file687.txt | file385.txt There is no fixed pattern while renaming & would... (20 Replies)
Discussion started by: crux123
20 Replies

7. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

8. UNIX for Dummies Questions & Answers

Renaming Multiple files

Hi All my dear friends I had multiple files in my directory with .pcv and .sqv extn I want to rename all .pcv files with .pc extn and all .sqv files with .sql extn Please help me out.:eek::mad::rolleyes: e.g. /trimsbld/users/dhirens/scripts/newfolder==>ll -rt total 2856 -rwxr-xr-x 1... (2 Replies)
Discussion started by: dhiren_shah
2 Replies

9. UNIX for Dummies Questions & Answers

Renaming of multiple filenames

Hi All, I need to rename the file names. I need to rename for example as follows file001 to flat1 file100 to flat100 Thanks Shash :confused: (7 Replies)
Discussion started by: shashi_kiran_v
7 Replies

10. Shell Programming and Scripting

Renaming multiple files

Can someone please tell me how I can rename a bunch of files at a time. I hava a directory that has 700+ files that are named *.xyz and I would like to rename them to *.abc . How can I do that with a simple command ? mv *.xyz *.abc did not work. Thanks in advance (4 Replies)
Discussion started by: jxh461
4 Replies
Login or Register to Ask a Question