Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > bulk copy and then rename files..

bulk copy and then rename files..
Thread Tools
vogueestylee
Fresh-Faced Recruit
Join Date: Jul 2011
Status: Offline
Reply With Quote
Jul 30, 2011, 09:19 AM
 
hi all hackers

will you help me? I would like to

1. copy files in directory with adding for example "-hd" into names..

so for example, when I got:

picture.png
picture2.png

after running the script I would like to have:

picture.png
picture2.png
picture-hd.png
picture2-hd.png



..so 4 files.. is it possible? Don't like automator, I preffer sh script for faster work,


and then I would like to use this script

Code:
#!/bin/bash\ for f in *.* do convert $f -resize 50% $f done
but ONLY for pictures without containg "-hd" in name..

using snow leo 10.6.8

how to do this?

or better way maybe:

1. make directory temp
2. copy *.jpg into temp
3. rename *.jpg to add "-hd"
4.run script to resize original non hd pictures
5. copy -hd from temp to base folder

how to do this?

thank you!
     
wrambro
Forum Regular
Join Date: Jan 2007
Location: Wisconsin
Status: Offline
Reply With Quote
Aug 7, 2011, 12:53 PM
 
Should be pretty easy to do without the extra overhead of creating the temp directory, moving files back and forth, etc.

Code:
#!/bin/bash for f in *.*; do echo "$f" nm=`echo "$f" | sed 's/.jpg/-hd.jpg/'` cp "$f" "$nm" convert -resize 50% "$nm" done
This is a good start, but has a few issues.
1) It will not discriminate between files you want to convert and files you've already converted. So if you run it twice, you'll end up with <filename>-hd-hd.jpg and it will be 25% of the original size
2) It will copy and try to convert all files (not just image files).

You can fix these issues modifying the script slightly:

Code:
#!/bin/bash for f in *.*; do if [[ "$f" == *.jpg && "$f" != *-hd.jpg ]]; then nm=`echo "$f" | sed 's/.jpg/-hd.jpg/'` cp "$f" "$nm" convert -resize 50% "$nm" fi done
Now the limitation is that the script will only handle .jpg files (not .jpeg, not .JPG, etc.) You can tweak the script so it can handle multiple extensions, but I'll leave that enhancement as a project for you
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:12 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,