Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    5

    Question Unanswered: This script doesn't work when a folder name is containing a space

    Hi friends,

    I'm using this script to compress a folder in a directory. I found that script only suitable for a folder name which not containing space (eg freelancers). But it won't work if this folder name is containing a space (free lancers). I would like to make this script more flexible, no matter what kind of folder name, it also work. So do you all have any idea? Thank you!!



    for folder in *
    do
    # Compress any folder found in the directories
    if [ -d $folder ]
    then
    tar zcvf $folder.tgz $folder
    rm -r $folder
    else
    echo “No folder was found,program is exiting..................”
    fi
    done

  2. #2
    Join Date
    Aug 2004
    Posts
    2
    >> if [ -d "$folder" ]
    >> then
    >> tar zcvf "$folder".tgz "$folder"
    >> rm -r "$folder"
    >> else
    >> echo “No folder was found,program is exiting..................”
    >> fi
    >> done

    If you put quotes round the variable folder you should be able to handle any directory name.

    Chris.
    Last edited by chrisgu; 08-12-04 at 10:49.

  3. #3
    Join Date
    Jul 2004
    Posts
    5

    Smile Thanks,Chris

    Thanks Chris you are the man..the script that you teach is working well. Thanks a lot!

Posting Permissions

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