Author Topic: 7-Zip is frustrating  (Read 2392 times)

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
7-Zip is frustrating
« on: Wednesday, November 09, 2011, 09:13:14 AM »
I've been a WinRAR user for a long time.  I like everything about the program: it has a well-designed GUI, rich command line interface, great compression, and good speed.  The only problem is that I frequently need to use something like WinRAR in the workplace to automate backups via scripts and even though WinRAR licenses are cheap, I'm usually instructed to use a free alternative.  Enter 7-Zip.

Don't get me wrong, I am an open-source supporter but 7-Zip is very clunky in comparison to WinRAR.  The GUI lacks many of the features accessible via command line and while creating a SFX archive is a snap in WinRAR, it is a horrible experience in 7-Zip.  To create a SFX archive in WinRAR you just check the appropriate box, go to the SFX options and pick amongst the plethora of options you want for the SFX archive, all of which are very intuitive.  The 7-Zip GUI has an SFX option, but all it does is make an EXE that extracts itself to the directory the EXE is contained in.  If you want to do something like build a compressed installer that extracts the archived files to a temporary folder and then calls a given EXE file to begin the installation after extraction here is what you have to do:

  • Create a regular 7-Zip archive of the installation files.
  • Create a text file in the same path as the 7Z file called config.txt containing specific syntax that describes the EXE file you want to call after extraction.  This file must be saved in UTF-8 format, not the normal Windows ANSI format.
  • Get the 7-Zip extras package, which is buried in the downloads and can be difficult to find.
  • Copy the 7zS.sfx file from the 7-Zip extras package to the same location as the 7Z and config.txt file
  • At the command line, run the command copy /b 7zS.sfx + config.txt + <archive name>.7z <desired sfx file name>.exe

It's just not intuitive at all.  Worse, the instructions for this were all from a third party, not from the 7-Zip documentation!  It's very confusing, as the main 7-Zip program contains a file called 7z.sfx, but if you try to use that instead of the 7zS.exe file from the extras package, double-clicking the EXE will just open a dialog asking you where you would like to extract the files.

And there is one nasty oversight in the design.  Rather than asking 7-Zip to archive files at a specific location or all files under a specific location, you can create a text file containing a specific list of files to archive.  But there is a catch: when it creates the archive, all the files from the list will just be placed at the root of the archive no matter where they are in the file system.  This means there can't be any duplicate names and it also means you lose the folder hierarchy within the archive.

This is a problem, because what I am doing at present is writing a PowerShell script that archives log files from the Microsoft IIS web server that are older than a certain number of days.  My script was working great until I encountered a web server that had multiple web sites running on it (and hence multiple log subdirectories).  I modified my script to accommodate more than one directory, but ran dead up against the duplicate file names issue since IIS logs are usually just e_<timestamp>.log.  So multiple sites can have log files with the same name.

I've asked around and various people are telling me to just call the parent log folder, but this is no good because it will not only include all log files rather than just those older than a certain number of days, but it will archive logs from other applications that I'm not interested in processing log files for.

This is just stupid design on the part of the 7-Zip programmers.  It should place files defined in the list file in the archives in a way that maintains the relative paths and folder hierarchy.  The worst part is I found someone had filed a feature request for this issue... in 2006.

Sure, 7-Zip is powerful, free, and provides the best compression there is.  But it's usability is some of the worst I've seen in open-source software.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: 7-Zip is frustrating
« Reply #1 on: Wednesday, November 09, 2011, 10:57:24 AM »
A-ha!  There is sort of a mode that makes it work.  If you format the paths inside the list file so that they don't contain the drive letter or backslash and then call 7z.exe from the folder that contains the first folder in the path, it will work.  It will put the files in the archive in their various folders as defined by the path.

So lets say I want to have 7-Zip store all the IIS logs in C:\Windows\system32\LogFiles\W3SVC1 and W3SVC2 (but not other subfolders under LogFiles).  I make a list file that contains the files in the following format:

Windows\system32\LogFiles\W3SVC1\e_111108.log
Windows\system32\LogFiles\W3SVC1\e_111109.log
Windows\system32\LogFiles\W3SVC2\e_111109.log

etc.

I'm just doing a Substring(3) on the full path of the file, which means it grabs only the characters starting with character 3.  The first character is character 0 and because Windows drive letters are always a single letter, are always followed by a single colon, and then a single backslash, this works.  The downside is that when I open the archive, I see a Windows folder and I have to drill down to get to the log files.  I'm trying to figure out a way to put the paths in like this:

W3SVC1\e_111108.log
W3SVC1\e_111109.log
W3SVC2\e_111109.log

Offline iPPi

  • Senior Member
  • *
  • Posts: 3,159
  • Roar!
Re: 7-Zip is frustrating
« Reply #2 on: Wednesday, November 09, 2011, 11:36:34 AM »
I've had the opportunity to use 7Zip in a Linux environment and didn't like it either.  I just recall having to redo some of the extractions because I forgot to extract as binary. 

I'm so far removed from the Information Technology industry though that I really can't say anymore than that.

Offline Cools!

  • Administrator
  • Veteran
  • *
  • Posts: 1,628
  • Let's burn.
Re: 7-Zip is frustrating
« Reply #3 on: Wednesday, November 09, 2011, 12:05:24 PM »
That's why I stick to using gzip/tar on Linux and Mac. Creating an archive that maintains the original directory structure is a breeze. Anyone in IT should be able to use gzip/tar. I never liked any of the alternatives on Windows and never bothered creating SFX archives.

Hopefully you get this resolved or find an alternative.

Offline idolminds

  • ZOMG!
  • Administrator
  • Forum god
  • *
  • Posts: 11,933
Re: 7-Zip is frustrating
« Reply #4 on: Wednesday, November 09, 2011, 01:16:25 PM »
Ive been using Jzip which is basically 7zip with a new GUI. Its not bad for what I use it for.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: 7-Zip is frustrating
« Reply #5 on: Wednesday, November 09, 2011, 01:27:50 PM »
That's why I stick to using gzip/tar on Linux and Mac. Creating an archive that maintains the original directory structure is a breeze. Anyone in IT should be able to use gzip/tar. I never liked any of the alternatives on Windows and never bothered creating SFX archives.

Hopefully you get this resolved or find an alternative.
Well, this is a Windows server.  If it was Linux or Mac I would definitely be using tar + gzip or maybe tar + bzip2.

And yes, I found a solution:

Code: [Select]
$IisLogsToArchive | ForEach-Object {$Path = $_.FullName;$New_Depth = 1;$Parts = $Path -Split "\\";$Parts[($Parts.Count - $New_Depth -1)..($Parts.Count -1)] -Join "\"} | Out-File -FilePath "$LogPath\$IisLogListFileName" -Encoding UTF8
Here is the code for the full path, with drive letter:

Code: [Select]
$IisLogsToArchive | Select-Object -ExpandProperty FullName | Out-File -FilePath "$LogPath\$IisLogListFileName" -Encoding UTF8
Obviously, it would have been easier to keep the full path.

Offline PyroMenace

  • Senior Member
  • *
  • Posts: 3,930
Re: 7-Zip is frustrating
« Reply #6 on: Wednesday, November 09, 2011, 01:29:49 PM »
I used to use winRAR back in the day when windows didn't have its own compressed file reader, but now I don't really have any use for a file compression program since I don't come upon formats that windows 7 can't understand.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: 7-Zip is frustrating
« Reply #7 on: Wednesday, November 09, 2011, 01:39:07 PM »
Yeah, but unless I am mistaken, Windows 7 can only create ZIP files, which I'm done with using.

Offline gpw11

  • Gold Member
  • *
  • Posts: 7,180
Re: 7-Zip is frustrating
« Reply #8 on: Wednesday, November 09, 2011, 08:08:12 PM »
Yeah, I'm pretty sure you need winRAR or 7zip (which I've toyed with and also don't really like, for far more superficial reasons than your own) for anything other than .zip files.

Offline Cobra951

  • Gold Member
  • *
  • Posts: 8,934
Re: 7-Zip is frustrating
« Reply #9 on: Wednesday, November 09, 2011, 11:50:37 PM »
How much are the WinRAR licenses compared to your time to figure out all this stuff?

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: 7-Zip is frustrating
« Reply #10 on: Thursday, November 10, 2011, 06:35:41 AM »
lol, probably less.  But I would have had to research what I was doing yesterday for WinRAR too.  Users in 7-Zip's forums were saying that 7-Zip was the only compression program that acted like that.  It was just a general complaint about 7-Zip.  Besides, I wrote my script to be as flexible as possible so it could be used on any Windows server.  Heck, it doesn't even have to be used for IIS logs.  It could be used for regularly archiving any sort of folder, though it makes the most sense for log files.  So it makes the most sense to leverage a free program.