command line - Extract and overwrite existing files

17
2014-04
  • Larry

    I am trying to write a batch script to extract files out of an existing zip file, into another folder on my desktop and to have the system not prompt me as to whether I want to overwrite the existing files or not. The script works with just -o but once I add -aoa, I get an error.

    "c:\program files\7-zip\7z.exe" e file1.zip "-aoac:\documents and settings\all users\desktop\all_backup_files"

  • Answers
  • Sean Cheshire

    the 7-zip command line options you will need are: x, -o and -y

    "c:\program files\7-zip\7z.exe" x file1.zip -o"c:\documents and settings\all users\desktop\all_backup_files" -y

    if you type 7z --help you will get a list of valid parameters


  • 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")