Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file renaming with spaces

Status
Not open for further replies.

bobbyfunk

Instructor
Oct 22, 2006
2
CA
hello there omniscienti...
in thread822-421475 there was some edifying discussion of how to create a script to batch-rename all the files in a directory from *.JPG to *.jpg. now that's close enough to what I want to do that I tried it.. i want to change the extension entirely, precisely from .rar to .cbr.
But! the problem is that some of these filenames have (gasp!) spaces in them (??!@#!@) and so the for loop variable is getting set to random words inside the names of these files. is there a super kühl way i can have the lines from the find statement go into the for assignment without getting corrupted?
I can change it to an underscore by piping it through sed s/ /_/g but then i lose the spaces. and it's kind of dirty. and plus I need to change them back (since some of the subfolder names have spaces in them) and there might be an actual _ in one of the filenames. thanks for yer ass is stance! and hey, if you need any scanned comic books...
Thanks..
-T
 
weeeelllll.... try not to talk to myself but hey... this actually works okay with the while loop approach, eg
find ... |while read file; do
...
done

but i'm still übercurious if there's a way to have the stuff that comes out of find be considered as a single argument to the for loop and other wee bastards.

so?

T

 
oldIFS="$IFS"
IFS="\n"
for ...
done
IFS="$oldIFS"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about something like:
[tt]
for f in *.rar; do # for each file
f=`echo $f | sed 's/\..*//'` # strip the suffix
mv "$f" "$f.jpg" # rename the file
done
[/tt]
 
That should of course have been:
[tt]
for f in *.rar; do # for each file
f=`echo $f | sed 's/\..*//'` # strip the suffix
mv "$f.rar" "$f.cbr" # rename the file
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top