batch file - Command line switching

25
2014-05
  • Larry

    I have read through some suggestions but I am just not technical enough to get this I think.

    I am a CAD designer and each file has 5 files associated with it. I have 3 sets of 5 files, and each set needs to go into its own zip file, placed on a separate server.

    For example:

    "C:\Program Files\7-zip\7z.exe"  a file1.zip "O:\server2\map files\BC\BC.d*"-0
    "C:\Program Files\7-zip\7z.exe"  a file2.zip "O:\server2\map files\BC\ON.d*"-0
    "C:\Program Files\7-zip\7z.exe"  a file3.zip "O:\server2\map files\BC\AB.d*"-0
    

    and I am in directory "S:\server\map files\provinces" (for example).

    These lines run within an existing batch file and by the time it reaches the 3 lines above, it's in the S: directory sample above. So it's looking on my pc for the 7-zip program, creating 3 zip file names which it does, but places those zip files on a separate server which it doesn't and the first zip file also includes all the other 10 files, the second zip file the same plus the first zip file, and the third the same with the other two zip files making me think the code isn't recognizing the part after file1.zip where I am trying to tell it what files to include and where to place the zip files.

    Ultimately, I want to either have the system create a new zip file if the old one was deleted, or copy the new files into the existing zip and overwrite any older files, and for these zip files to be placed in a separate location which is where we share our files with other personnel from within our company. The S: drive is for all originals, and O: is for sharing.

    Is there a list of all switching options with many different samples?

    SOLUTION

    Okay! I think I tried every single possible (possible not meaning every scenario worked), way to order the above code and I final have it.

    "c:\program files\7-zip\7z.exe" u "O:\server2\map files\BC\file1.zip" bc.d*,

    where

    "c:\program files\7-zip\7z.exe" is the location of the program itself (often referred to as the 'verb' or action word of the sentence - or the act of compression,

    u versus using a either creates an archive (in my case a .zip file since I didn't specify to the system that I wanted it to create a compressed folder of another format), if one doesn't exist or only updates/compresses new versions of the files to an existing archive if an archive already exists.

    "O:\server2\map files\BC\file1.zip" is the location where the zip file will be created or updated and the name to give the archive or name of existing archive,

    finally followed by the names of the files (bc.d*) you want to include in the archive. There are 5 files that start with bc with different extensions and the extensions also start with d. DBG, DBN, DBI, DBQ, and DBA. using the * or asterisk, tells the system to copy all files named bc with extensions staring with d. The reasoning for this, is our CADD files can sometimes have other supporting files but their extensions would not begin with d and they are also not important enough to want to archive.

    Great little program that just solved a lifetime issue we have been having. Thanks 7-zip.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    What is 7-Zip’s command-line argument to create a self extracting archive?
  • djangofan

    I looked everywhere and couldn't find a straight answer from anyone.

    If I want to package the contents of C:\Temp into a file called Temp.exe (in 7z format) that is self-extracting, how do I do it in a batch file?

    This doesn't work:

    "C:\Program Files\7-Zip\7z.exe" a -t7z -mx5 -sfx 7z.sfx directoryname archive.exe -mmt
    

    What I get from that is a self extracting archive called 7z.sfx . Can't figure this out.


  • Related Answers
  • MrPhilTX

    The issue you were having is that 7-zip doesn't like spaces in the arguments. So what you wanted was something more like:

    "C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx7z.sfx dirname
    
  • Daisetsu

    With 7-zip there is command line version available called 7z.exe you can download it from 7-zip's website. To create a self extracting installer use the -sfx flag followed by a number for the compression amount.

  • djangofan

    I figured it out after fiddling with it:

    :: zip
    "C:\Program Files\7-Zip\7z.exe" a archive.exe -mmt -mx5 -sfx dirname
    pause
    
  • Sathya

    This should work:

    "C:\Program Files\7-Zip\7z.exe" a -t7z -mx5 -sfx archive.exe directoryname -mmt
    

    (PS: Add Program Files\7-zip to your PATH environment variable, there by you can access the file directly as 7z.exe rather than "C:\Program Files\7-Zip\7z.exe")