Results 1 to 3 of 3

Thread: Zip all folders that reside in the main folder

  1. #1
    Join Date
    Nov 2007
    Beans
    18

    Exclamation Zip all folders that reside in the main folder

    Hello, I would like to zip all the folder I have in a folder (Lets call this folder zip). If their are any folders inside of zip I want it to zip them. I am currently trying to make this into a shell script. If you have any advice please help

    Thanks,
    Flashuni

  2. #2
    Join Date
    Apr 2008
    Location
    Phoenix, AZ
    Beans
    1,393
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Zip all folders that reside in the main folder

    I'm not sure about what you mean when you say folders inside of a zip file. Why not just do a recursive zip in the first place.
    Code:
    zip -r files.zip /dir

    That will zip everything in /dir and any of its subdirectories.

  3. #3
    Join Date
    Nov 2007
    Beans
    18

    Re: Zip all folders that reside in the main folder

    Code:
    ## zip the contents of each folder in the current directory into an archive:
    for d in *; do if [ -d "$d" ]; then cd "$d"; cd ..; fi; done
    
    ## zip every folder in the current directory into an archive:
    for d in *; do if [ -d "$d" ]; then zip -r "$d.zip" "$d"; fi; done
    
    ## example recursively forces the deletion of the directory if zip returns true:
    for d in *; do
            if [ ! -d "$d" ]; then
                    continue
            fi
            if ! zip -r "$d.zip" "$d"; then
                    continue
            fi
    done
    Figured it out. Automatically finds any folder and zips it.

Bookmarks

Posting Permissions

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