Register
It is currently Tue Jul 29, 2014 12:50 pm

rename jpgs to numbers


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Aug 11, 2005 9:56 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 664
Location: Des Moines, Iowa
Had someone request a script that would rename all images to numbers ....

came up with this....

------

Code:
#!/bin/bash
# Rename .jpgs with numbers
n=1
for i in *[.jpg,.JPG] ;
do
mv $i $n.jpg;
n=$(( $n+1 ));
done
exit


Top
 Profile WWW  
 PostPosted: Thu Aug 11, 2005 9:32 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
i just had a concern cross my mind... not sure if it holds any weight, and i'm not sure how to test it...
if there were a couple hundred images in the directory (say 300), and you did the above script, once it finished renaming the ones listed, what's to keep it from continueing on and renaming file #1 to file #301 etc.?

:: update ::
well... i tested it with 100 files, no problems from above...
but something else came up... in the line:
Code:
mv $i $n.jpg;

it would be best to have:
Code:
mv "$i" "${n}.jpg";

that way if any files have a space in the name, it won't error
:)


Top
 Profile  
 PostPosted: Fri Sep 09, 2005 11:57 pm   

Joined: Sat Jun 04, 2005 3:16 am
Posts: 16
Location: That Lunar Colony That Everybody Denies the Existance of.
It wouldnt know about file 1.jpg, because the for loop is only run once, it would generate a list of all the jpeg files before any filename modifications are made and that list is not modified, except to move you down that list.

You might do something with file to locate jpeg files with literally .jpeg or .Jpg as the extension. or even sometimes a jpg can get renamed to a .gif or some other extention.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP