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.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Copying Multiple filenames having whitespaces

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-04, 22:25
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
Copying Multiple filenames having whitespaces

I read a few posts on the topic of handling filenames with spaces but need some help on this one . I need to copy multiple files each of which have wihtespace to another direcotry .
for e.x i have a variable called cpfiles i.e
cpfiles="PSGIMG_1398_PSGMKT_IMG_FILENAME_2.0 Portable Mutli-Bur.gif" "PSGIMG_1398_PSGMKT_IMG_FILENAME_3.0 Portable Mutli-Bur.gif"

and in the next statement when i do
cp $cpfiles ./myimages ..
it simply fails stating
cp PSGIMG_1398_PSGMKT_IMG_FILENAME_2.0 .: File does not exist .
THis is mainly because of the Whitespace in the filesnames . How do I do it .. I have about 10,000 files like this to copy .
Any help would be appreciated.
Thanks
Saurav
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 07:09
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Yow do you select files to copy ?
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-15-04, 09:40
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
If cpfiles represents a singular file as your post suggests...

cp "$cpfiles" ./myimages
Reply With Quote
  #4 (permalink)  
Old 04-15-04, 18:07
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
Following is my script:
The list of images are in a file called images.list .. so it has about 10,000 lines
cpfiles=""
counter=0
IMAGECOPYCOUNTER=100
exec <imagefiles.list
while read line
do
cpfiles="$cpfiles \"$line\""
(( counter = counter + 1 ))
(( remainder = counter % IMAGECOPYCOUNTER))
if [ $remainder -eq 0 ];then
cp "$cpfiles" ./myimages
cpfiles=""
fi
done
This is failing at the cp "$cpfiles" step when Images filenames have a space in them .
Any suggestions would be helpfull .
Reply With Quote
  #5 (permalink)  
Old 04-16-04, 03:12
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Try this modiufied version of your script :
Code:
cpfiles=""
counter=0
IMAGECOPYCOUNTER=100
exec <imagefiles.list
while read line
do
   cpfiles="$cpfiles \"$line\""
   (( counter = counter + 1 ))
   (( remainder = counter % IMAGECOPYCOUNTER))
   if [ $remainder -eq 0 ];then
      eval cp $cpfiles ./myimages
      cpfiles=""
   fi
done
Attention, if the number of files to copy is not exactly a multiple of 100, some files will not be copied.

You can also do the work with tar depending of your Unix flavor.
If the -T option (-I for some systems) is supported :
Code:
tar cTf imagefiles.list - | ( cd myimages; tar xf - )
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting 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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On