1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ZIP: howto store directory in the zip-file

Discussion in 'Support' started by Frank, Jan 22, 2013.

  1. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I have a directory where I store my means for work in subdirectories again.
    Now I want to zip some of these old subdirs in one zip-file.
    But I can't find a switch/option to store them with its directory name like in 7zip.
    Example:

    R:\robocopy >zip /a old_stuff.zip 20111108_amd-hd5\*.*
    <= R:\robocopy\20111108_amd-hd5\filer-commands_amd-diverse.xlsx
    <= R:\robocopy\20111108_amd-hd5\amd-hd5_20111008191729.log
    <= R:\robocopy\20111108_amd-hd5\robocopy-amd-hd5.btm

    R:\robocopy >zip /v old_stuff.zip
    2011-08-07 20:47 13,186 21% filer-commands_amd-diverse.xlsx
    2011-10-08 20:54 1,296 64% amd-hd5_20111008191729.log
    2011-10-08 18:15 9,026 65% robocopy-amd-hd5.btm

    R:\robocopy >
    R:\robocopy >7za a old_stuff.7z 20111108_amd-hd5\*.*

    7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
    Scanning

    Creating archive old_stuff.7z

    Compressing 20111108_amd-hd5\robocopy-amd-hd5.btm
    Compressing 20111108_amd-hd5\amd-hd5_20111008191729.log
    Compressing 20111108_amd-hd5\filer-commands_amd-diverse.xlsx

    Everything is Ok

    R:\robocopy >7za l old_stuff.7z

    7-Zip (A) 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

    Listing archive: old_stuff.7z

    --
    Path = old_stuff.7z
    Type = 7z
    Method = LZMA
    Solid = +
    Blocks = 1
    Physical Size = 13989
    Headers Size = 269

    Date Time Attr Size Compressed Name
    ------------------- ----- ------------ ------------ ------------------------
    2011-10-08 18:15:51 ....A 9026 13720 20111108_amd-hd5\robocopy-amd-hd5.btm
    2011-10-08 20:54:43 ....A 1296 20111108_amd-hd5\amd-hd5_20111008191729.log
    2011-08-07 20:47:33 ....A 13186 20111108_amd-hd5\filer-commands_amd-diverse.xlsx
    ------------------- ----- ------------ ------------ ------------------------
    23508 13720 3 files, 0 folders
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Doesn't /R ("recurse") work? BTW, 7z is capable of better overall compression than ZIP if you have it archive all files as a unit (IIRC "block mode").
     
  3. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    You need to use the "/r" switch, however you need to work a directory above the directory name you actually want to save.

    So for your amd-hd5 folder you'd need a structure like
    Code:
    [Z:\temp]
    12:08:02 $ tree /a /f
    Z:\temp
    \--20111108_amd-h5
      +  amd-hd5_20111008191729.log
      +  filer-commands_amd-diverse.xlsx
      \  robocopy-amd-hd5.btm
    and then (as seen in my example) run the zip command from z:\
    Code:
    [Z:\]
    12:09:41 $ zip /r old_stuff.zip temp\*.*
    <= Z:\temp\20111108_amd-h5\*
     
    0:00:00.017
    [Z:\]
    12:10:16 $ zip /v old_stuff.zip
    2013-01-22  12:06             1 100%  20111108_amd-h5\
    2013-01-22  12:06            13 -15%  20111108_amd-h5\amd-hd5_20111008191729.log
    2013-01-22  12:06            13 -15%  20111108_amd-h5\filer-commands_amd-diverse.xlsx
    2013-01-22  12:06            13 -15%  20111108_amd-h5\robocopy-amd-hd5.btm
     
  4. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Thank you for the advice (honestly). I know there is the /R switch. But what if my work-dirs would be settled directly unter the root dir?
     
  5. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    OK, I recall my last post.
    This example does what I want. Let's say I backup my switch-configs every friday and want to store them from time to time in a zip-file:
    Code:
    V:\ >tree /f /a
     
    V:\
    +--2013-01-04
    |  +  switch1.cfg
    |  +  switch2.cfg
    |  +  switch3.cfg
    |  \  switchx.cfg
    +--2013-01-11
    |  +  switch1.cfg
    |  +  switch2.cfg
    |  +  switch3.cfg
    |  \  switchx.cfg
    \--2013-01-18
      +  switch1.cfg
      +  switch2.cfg
      +  switch3.cfg
      \  switchx.cfg
     
    V:\ >zip /r /a configs v:\*.*
    <= V:\2013-01-04\*
    <= V:\2013-01-11\*
    <= V:\2013-01-18\*
     
    V:\ >zip /v configs.zip
    2013-01-22  19:37              1 100%  2013-01-04\
    2013-01-22  19:37              2 -100%  2013-01-04\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switchx.cfg
    2013-01-22  19:37              1 100%  2013-01-11\
    2013-01-22  19:37              2 -100%  2013-01-11\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switchx.cfg
    2013-01-22  19:37              1 100%  2013-01-18\
    2013-01-22  19:37              2 -100%  2013-01-18\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switchx.cfg
    
    But that's not the same and a little bit more difficult as the 7zip behavior.

    And if I specify explicit one directory I get the same trouble:

    Code:
    V:\ >zip /r /a configs v:\2013-01-04\*.*
    <= V:\2013-01-04\switch1.cfg
    <= V:\2013-01-04\switch2.cfg
    <= V:\2013-01-04\switch3.cfg
    <= V:\2013-01-04\switchx.cfg
     
    V:\ >zip /v configs.zip
    2013-01-22  19:37              1 100%  2013-01-04\
    2013-01-22  19:37              2 -100%  2013-01-04\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-04\switchx.cfg
    2013-01-22  19:37              1 100%  2013-01-11\
    2013-01-22  19:37              2 -100%  2013-01-11\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-11\switchx.cfg
    2013-01-22  19:37              1 100%  2013-01-18\
    2013-01-22  19:37              2 -100%  2013-01-18\switch1.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switch2.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switch3.cfg
    2013-01-22  19:37              2 -100%  2013-01-18\switchx.cfg
    2013-01-22  19:37              2 -100%  switch1.cfg
    2013-01-22  19:37              2 -100%  switch2.cfg
    2013-01-22  19:37              2 -100%  switch3.cfg
    2013-01-22  19:37              2 -100%  switchx.cfg
    
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    ... which means you cannot start the archiving in the ROOT directory, hence you cannot archive a WHOLE drive! This may not seem like a major restriction for a terabyte drive, but it sure is for most pocket drives...
     
  7. BobK

    Joined:
    Sep 11, 2009
    Messages:
    35
    Likes Received:
    0
    Assuming it's a strange anomaly in 7Zip, and as I don't have 7Zip, but couldn't you use: Z: 7zip ..\etc .. ?

    I just tried: C:dir , C:dir \. & C:dir \.. ... all showed the same,
     
  8. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Well, I was wrong... This command works to create c.zip in _CWD and starts to compress all files on C:
    Code:
    zip /a:-j-h-s /i /l6 /p /r c.zip C:\*
    BUT!
    1/ Once it enters the subdirectory C:\Documents and Settings it seems to die
    2/ The report by UNZIP /V of an empty (0-byte) file displays 1 byte, and compression of -100%
     
  9. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I think it is no "strange anomaly", e.g. RAR works this way, too.
    Code:
    V:\ >rar a old_stuff 2013-01-04\*.*
     
    RAR Deutsche Version 3.20 beta 4      (c) 1993-2003 Eugene Roshal        21.Apr.2003
     
    Shareware Version              Geben Sie RAR -? für Hilfe ein.
     
    Unregistrierte Version. Bitte lassen Sie sich registieren
     
    Erstelle Archiv old_stuff.rar
     
    Archiviere 2013-01-04\switch1.cfg                                     OK
    Archiviere 2013-01-04\switch2.cfg                                     OK
    Archiviere 2013-01-04\switch3.cfg                                     OK
    Archiviere 2013-01-04\switchx.cfg                                     OK
    Fertig
    V:\ >rar v old_stuff
     
    RAR Deutsche Version 3.20 beta 4      (c) 1993-2003 Eugene Roshal        21.Apr.2003
     
    Shareware Version              Geben Sie RAR -? für Hilfe ein.
     
    Archiv old_stuff.rar
     
    Dateiname/Kommentar
                    Größe  Gepak. Verh.  Datum  Zeit    Attr      CRC  Meth Ver
    -------------------------------------------------------------------------------
    2013-01-04\switch1.cfg
                        2        2 100% 22-01-13 19:37  .....A  14A285AC m0b 2.9
    2013-01-04\switch2.cfg
                        2        2 100% 22-01-13 19:37  .....A  14A285AC m0b 2.9
    2013-01-04\switch3.cfg
                        2        2 100% 22-01-13 19:37  .....A  14A285AC m0b 2.9
    2013-01-04\switchx.cfg
                        2        2 100% 22-01-13 19:37  .....A  14A285AC m0b 2.9
    -------------------------------------------------------------------------------
        4                8        8 100%
    
     
  10. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Using the current built in ZIP, you won't be able to store the path names unless you drop your working directories into a subdirectory and continue working from the parent.

    Going back to your original 7zip example, why don't you just change this...
    ... to this ...
    Code:
    [Z:\]
    13:50:38 $ 7z a old_stuff.zip 20111108_amd-hd5
     
    7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18
    Scanning
     
    Creating archive old_stuff.zip
     
    Compressing  20111108_amd-hd5\amd-hd5_20111008191729.log
    Compressing  20111108_amd-hd5\filer-commands_amd-diverse.xlsx
    Compressing  20111108_amd-hd5\robocopy-amd-hd5.btm
     
    Everything is Ok
     
    0:00:00.181
    [Z:\]
    13:50:44 $ zip /v old_stuff.zip
    2013-01-22  13:48              1 100%  20111108_amd-hd5\
    2013-01-22  13:48             13   0%  20111108_amd-hd5\amd-hd5_20111008191729.log
    2013-01-22  13:48             13   0%  20111108_amd-hd5\filer-commands_amd-diverse.xlsx
    2013-01-22  13:48             13   0%  20111108_amd-hd5\robocopy-amd-hd5.btm
    Edit: Actually, that looks better than using the built in ZIP... the compression percentages aren't screwed up when using 7zip like they are when using the built in ZIP.
     
  11. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I like 7zip and use it on machines where I don't have a licensed copy of take command.
    But the main disadvantage of 7zip is, that it doesn't have a MOVE option. You can only add files.
    And actually I want to clean up my directories and not to double them ;)

    I just want a new zip-option to add files with it's "superordinate" directory.
     
  12. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Wow. I never noticed that before. I just looked through the docs and there is no mention of "move"ing files. There's updates and other such, but no "move". How 'bout that?!

    Have you looked at Info-ZIP? It has a move, handles directories without problems, and doesn't screw up the compression percentages.
     
  13. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I'm not shure if this is what I want. On the first glance: yet an additional tool, pretty old, 2 programs for zip/unzip, needs its DLLs and so on.
    Thanks anyway.
     
  14. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,874
    Likes Received:
    30
    InfoZip works well. I have used it for years. My version is stand-alone. [And ZIP technology itself if pretty old!]
     
  15. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,874
    Likes Received:
    30
    And it's not all that old.
    Code:
    u:\> zip.exe
    Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
    Zip 3.0 (July 5th 2008). Usage:
    zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
      The default action is to add or replace zipfile entries from list, which
      can include the special name - to compress standard input.
      If zipfile and list are omitted, zip compresses stdin to stdout.
      -f  freshen: only changed files  -u  update: only changed or new files
      -d  delete entries in zipfile    -m  move into zipfile (delete OS files)
      -r  recurse into directories    -j  junk (don't record) directory names
      -0  store only                  -l  convert LF to CR LF (-ll CR LF to LF)
      -1  compress faster              -9  compress better
      -q  quiet operation              -v  verbose operation/print version info
      -c  add one-line comments        -z  add zipfile comment
      -@  read names from stdin        -o  make zipfile as old as latest entry
      -x  exclude the following names  -i  include only the following names
      -F  fix zipfile (-FF try harder) -D  do not add directory entries
      -A  adjust self-extracting exe  -J  junk zipfile prefix (unzipsfx)
      -T  test zipfile integrity      -X  eXclude eXtra file attributes
      -!  use privileges (if granted) to obtain all aspects of WinNT security
      -$  include volume label        -S  include system and hidden files
      -e  encrypt                      -n  don't compress these suffixes
      -h2  show more help
     
  16. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,012
    Likes Received:
    0
    There is also PKZip Command Line for windows. They have several different versions too. Even SecureZip. I am a few versions old but it does have:

    Code:
    PKZIP(R)  Version 8.10  ZIP Compression Utility for Windows
    Copyright (C) 1989-2005 PKWARE, Inc.  All Rights Reserved. Registered Version
    PKZIP Reg. U.S. Pat. and Tm. Off.  Patent No. 5,051,745
    Patent Pending
     
     
    Usage: PKZIPC [command] [options] zipfile [@list] [files...]
     
      View .zip file contents: PKZIPC zipfile
     
      Create a .zip file:      PKZIPC -add zipfile file(s)...
     
      Extract files from .zip: PKZIPC -extract zipfile
     
    The above usages are only basic examples of PKZIP's capability.
     
     
     
    Press any key to continue or <Esc> to exit
     
      PKZIP Commands:
    Add                Encode              Help                MailTo
    Comment            EnterLicenseKey    License            Print
    Configuration      Extract            ListCertificates    Sfx
    Console            Fix                ListCryptAlgorithms Test
    Default            FTP                ListFile            Version
    Delete              Header              ListSfxTypes        View
     
    Enter 'C' to list Commands, or 'O' to list Options
    Enter the command or option for additional help, <Esc> to exit
     
    Command/Option? o
     
     
      PKZIP Options:
    204            Directories      Log          Newer              SfxDirectories
    After          Embedded          LogError      NoArchiveExtension SfxLogfile
    AltConfig      Encode            LogOptions    NoExtended        SfxOverwrite
    ArchiveDate    Error            Lowercase    NoFix              SfxUIType
    ArchiveType    Exclude          MailBCC      Normal            Shortname
    ASCII          Fast              MailBody      NoSmartCard        Sign
    Attributes    FTP              MailCC        Older              Silent
    AVArgs        Hash              MailFrom      OptionChar        Smaller
    AVScan        Header            MailOptions  Overwrite          SnmpTrapHost
    Before        Include          MailReplyTo  Password          Sort
    Binary        JobID            MailServer    Path              Span
    BUCC          KeyFile          MailSubject  Permission        Speed
    BZIP2          KeyPassphrase    MailTo        Preview            Store
    CD            Larger            Mask          Priority          Temp
    Certificate    LDAP              Maximum      Recipient          Times
    Comment        Level            More          Recurse            Translate
    CryptAlgorithm ListChar          Move          RunAfter          Warning
    DCLImplode    ListFile          MoveArchive  Sfx                Wipe
    Deflate64      Locale            NameSfx      SfxDestination
     
    Enter 'C' to list Commands, or 'O' to list Options
    Enter the command or option for additional help, <Esc> to exit
     
    Command/Option?
    PKZIpc -add -max -move -dir <ZipfileName> <PathtoZip>

    The -dir switch implies recurse and path storage.
     
  17. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Yesterday I must have caught a weird version of info-zip. Now I obviously downloaded the version that you use.
    And I have to admit: It has many functions and does what I expect: preserve the directory in the zip-file when I zip a directory.
     
  18. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Glad to hear it. Very handy program. Doesn't come close to RAR when it comes to command line switches, but more than enough to get the job done. (here's RAR command line for comparison to vefatica's message above)
    Code:
    14:24:39 $ rar
     
    RAR 4.20   Copyright (c) 1993-2012 Alexander Roshal   9 Jun 2012
    Registered to **** ******
     
    Usage:     rar <command> -<switch 1> -<switch N> <archive> <files...>
                   <@listfiles...> <path_to_extract\>
     
    <Commands>
      a             Add files to archive
      c             Add archive comment
      cf            Add files comment
      ch            Change archive parameters
      cw            Write archive comment to file
      d             Delete files from archive
      e             Extract files to current directory
      f             Freshen files in archive
      i[par]=<str>  Find string in archives
      k             Lock archive
      l[t,b]        List archive [technical, bare]
      m[f]          Move to archive [files only]
      p             Print file to stdout
      r             Repair archive
      rc            Reconstruct missing volumes
      rn            Rename archived files
      rr[N]         Add data recovery record
      rv[N]         Create recovery volumes
      s[name|-]     Convert archive to or from SFX
      t             Test archive files
      u             Update files in archive
      v[t,b]        Verbosely list archive [technical,bare]
      x             Extract files with full path
     
    <Switches>
      -             Stop switches scanning
      @[+]          Disable [enable] file lists
      ac            Clear Archive attribute after compression or extraction
      ad            Append archive name to destination path
      ag[format]    Generate archive name using the current date
      ai            Ignore file attributes
      ao            Add files with Archive attribute set
      ap<path>      Set path inside archive
      as            Synchronize archive contents
      av            Put authenticity verification (registered versions only)
      av-           Disable authenticity verification check
      c-            Disable comments show
      cfg-          Disable read configuration
      cl            Convert names to lower case
      cu            Convert names to upper case
      df            Delete files after archiving
      dh            Open shared files
      dr            Delete files to Recycle Bin
      ds            Disable name sort for solid archive
      dw            Wipe files after archiving
      e[+]<attr>    Set file exclude and include attributes
      ed            Do not add empty directories
      en            Do not put 'end of archive' block
      ep            Exclude paths from names
      ep1           Exclude base directory from names
      ep2           Expand paths to full
      ep3           Expand paths to full including the drive letter
      f             Freshen files
      hp[password]  Encrypt both file data and headers
      id[c,d,p,q]   Disable messages
      ieml[addr]    Send archive by email
      ierr          Send all messages to stderr
      ilog[name]    Log errors to file (registered versions only)
      inul          Disable all messages
      ioff          Turn PC off after completing an operation
      isnd          Enable sound
      k             Lock archive
      kb            Keep broken extracted files
      log[f][=name] Write names to log file
      m<0..5>       Set compression level (0-store...3-default...5-maximal)
      mc<par>       Set advanced compression parameters
      md<size>      Dictionary size in KB (64,128,256,512,1024,2048,4096 or A-G)
      ms[ext;ext]   Specify file types to store
      mt<threads>   Set the number of threads
      n<file>       Include only specified file
      n@            Read file names to include from stdin
      n@<list>      Include files listed in specified list file
      o[+|-]        Set the overwrite mode
      oc            Set NTFS Compressed attribute
      or            Rename files automatically
      os            Save NTFS streams
      ow            Save or restore file owner and group
      p[password]   Set password
      p-            Do not query password
      r             Recurse subdirectories
      r-            Disable recursion
      r0            Recurse subdirectories for wildcard names only
      ri<P>[:<S>]   Set priority (0-default,1-min..15-max) and sleep time in ms
      rr[N]         Add data recovery record
      rv[N]         Create recovery volumes
      s[<N>,v[-],e] Create solid archive
      s-            Disable solid archiving
      sc<chr>[obj]  Specify the character set
      sfx[name]     Create SFX archive
      si[name]      Read data from standard input (stdin)
      sl<size>      Process files with size less than specified
      sm<size>      Process files with size more than specified
      t             Test files after archiving
      ta<date>      Process files modified after <date> in YYYYMMDDHHMMSS format
      tb<date>      Process files modified before <date> in YYYYMMDDHHMMSS format
      tk            Keep original archive time
      tl            Set archive time to latest file
      tn<time>      Process files newer than <time>
      to<time>      Process files older than <time>
      ts<m,c,a>[N]  Save or restore file time (modification, creation, access)
      u             Update files
      v             Create volumes with size autodetection or list all volumes
      v<size>[k,b]  Create volumes with size=<size>*1000 [*1024, *1]
      vd            Erase disk contents before creating volume
      ver[n]        File version control
      vn            Use the old style volume naming scheme
      vp            Pause before each volume
      w<path>       Assign work directory
      x<file>       Exclude specified file
      x@            Read file names to exclude from stdin
      x@<list>      Exclude files listed in specified list file
      y             Assume Yes on all queries
      z[file]       Read archive comment from file
     
  19. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Unfortunatelly it's not easy in our company to buy multi-system licenses. I can't say "hey - I need a TakeCommand license for all my systems" or "WinRAR for all my servers" ...
    In the opposite it's easier to buy the big, fat and really expensive ones.
    So I allways try to use free software. And nowadays there are many communities or enthusiasts who develop cool software for a low price...
    I'm not happy with this situation, but that's the status quo.
     
  20. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    So, apparently InfoZip has more features than I originally thought. Try the following command for the "extended help"...
    Code:
    infozip -h2
     
  21. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Thanks, I already became fond of info-zip :) and incorporated it in some production scripts.
    Thereby I found out that all my oracle installations also use info-zip!
     

Share This Page