+ Post New Thread
Results 1 to 6 of 6
Coding Thread, Scripting a zip operation in Coding and Web Development; Can anyone point me in the right direction to do the following I have a series of users folders that ...
  1. #1

    Join Date
    Jul 2011
    Location
    Kent
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Scripting a zip operation

    Can anyone point me in the right direction to do the following

    I have a series of users folders that I need to zip to individual zip files. ie:

    Input folders
    A
    B
    C

    Output:
    A.zip
    B.zip
    C.zip

    All the input folders will have subdirectories and files. There will be several hundred folders so I must automate it.

    I don't expect anyone to write a solution, but any pointers will be appreciated!

    Many thanks,
    David

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,696
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    If you install 7zip commandline version it will work command line easy enough.

    Examples: 7-Zip Command-Line Examples

    Steve

  3. #3


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    A script isn't needed for something this simple - you can do it all on the command line in a single line

    Code:
    find . -type d -maxdepth 1 -exec zip -r {} /path/you/want/the/files/to/go/in  \;

  4. #4

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    7 Zip is the way to go - have fun.......
    I've quite a few scripts using the command line on that - it hurts [ especially as some of mine have folders to exclude ] but once done it's rather good.
    Note - if you are going to automate or have something running as a schedule then I suggest piping it all to a file so you have a log.
    Example:

    "c:\program files\7-zip\"7z.exe a d:\matt\LON.7z d:\Matt\files -mx9 -ssw -xr!pdf_out -xr!csv_out -xr!man_rpts -xr!cust_rpt -y>d:\matt\log.txt"

    Will zip everything in the files folder but will exclude the folder names after the -xr! switch. It pipes it all to a text file for me to go over.
    Last edited by mattx; 9th January 2013 at 03:26 PM.

  5. #5


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,899
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    These batch files may help. The second one includes the parent folder in the zip file, while the first doesn't.

    Code:
    @echo off
    :: Location of 7za.exe
    SET EXE="C:\Program Files (x86)\7-Zip\7za.exe"
    
    for /D %%a in (*) do (
        cd "%%a"
        %EXE% a -t7z -m0=lzma2 -r -y -xr!*.tmp -xr!.ds_store -xr!thumbs.db -xr!~$*.* -xr!desktop.ini "..\%%a.7z" *
        cd ..
    )
    Code:
    @echo off
    :: Location of 7za.exe
    SET EXE="C:\Program Files (x86)\7-Zip\7za.exe"
    
    for /D %%a in (*) do (
        cd "%%a"
        %EXE% a -t7z -m0=lzma2 -r -y -xr!*.tmp -xr!.ds_store -xr!thumbs.db -xr!~$*.* -xr!desktop.ini "..\%%a.7z" "..\%%a\"
        cd ..
    )

  6. #6


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    Quote Originally Posted by Arthur View Post
    These batch files may help. The second one includes the parent folder in the zip file, while the first doesn't.
    Ouch. I prefer my one liner !

SHARE:
+ Post New Thread

Similar Threads

  1. Script to run on certain Operating Systems?
    By CallumCatterall in forum Scripts
    Replies: 15
    Last Post: 29th November 2011, 09:50 PM
  2. Replies: 16
    Last Post: 9th December 2010, 09:10 PM
  3. Replies: 3
    Last Post: 6th December 2006, 11:01 PM
  4. Action Scripting in Flash
    By StewartKnight in forum Web Development
    Replies: 11
    Last Post: 4th June 2006, 11:23 AM
  5. The KiXtart free-format scripting language
    By ninjabeaver in forum Downloads
    Replies: 10
    Last Post: 16th June 2005, 12:11 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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