Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    19

    Unanswered: 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

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Yow do you select files to copy ?
    Jean-Pierre.

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    If cpfiles represents a singular file as your post suggests...

    cp "$cpfiles" ./myimages

  4. #4
    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 .

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •