It is currently Wed May 23, 2018 12:53 am

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: 693
Location: Des Moines, Iowa
Had someone request a script that would rename all images to numbers ....

came up with this....


# Rename .jpgs with numbers
for i in *[.jpg,.JPG] ;
mv $i $n.jpg;
n=$(( $n+1 ));

 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:
mv $i $n.jpg;

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

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

 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.

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 8 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