How can I verify the content of a zip archiv?
I need to verify the content of a zip archiv that is created by one of our applications.
I want to make sure that all files that are expected to be in the archiv are actually included.
I checked the slPacker object, but it does not support reading the content of an archiv.
Any ideas would be apprechiated.
hanks and regards,
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
To unzip an archive from script, you need to run the needed archiver with command-line parameters. After unzipping, you can get the contents of the archive (see the example below that uses the 7-Zip free archiver) and then analyze them.
var contents = readArchive("C:\\file.zip");
for (i = 0; i < contents.length - 1; i++)
var folder = extractArchive(archive)
var list = slPacker.GetFileListFromFolder(folder);
var aFile = list.split(chr(13)+chr(10));
var archiverExecutable = "\"C:\\Program Files (x86)\\7-Zip\\7z.exe\"";
var toFolder = "C:\\temp\\extracted\\";
var cmdLine = archiverExecutable + " x " + archive + " -o" + toFolder;
var WshShell = Sys.OleObject("WScript.Shell")
WshShell.Run(cmdLine, 5, true)
Customer Care Manager
thanks a lot for your input!
With the code sample I was able to do the verification (I use Delphi script). Strangely, 7-zip did not like the zip file, but with WinRar I could do the same and had no problems expanding the zip.
PS: Maybe you want to consider beefing up the spPacker object so working with zip-archives does not depend on 3rd party products.
Can you manually explore the contents of that file by using the 7-Zip file manager?
As for the slPacker object's functionality, we have an appropriate suggestion in our DB, and your post has increased its rating. Thank you.
Customer Care Manager
if you do not want to unpack the whole archive, you can also use the internal file listing of the archive. Most zip tools support creating this list (for 7-zip it is the command line switch -l). After creation, and piping it to a text file, you can parse the list or compare it to a reference listing.
You can also use a .NET Assembly for handling zip files via TestCompletes CLR Bridge, for example DotNetZip. This will offer you a lot routines for handling zip files and you do not need to handle external zip listing files.
TC 7.52/8.70/9.20 Standard, DelphiScript
no, the ZIP-file (created with VCL-zip from one of our apps) could not be opened by 7-zip in the explorer.
However, WinRar supports a similar command line interface and I could open the zip with WinRar without problems.
thanks for your suggestion.
I try to design our tests with as little dependencies to external tools as possible. Also, I want to do as little coding in our tests as necessary and use keyword tests wherever possible. I have to explain the tests to non-developers, so the more tools and code I have the more complicated it gets.
In my optinion support for working with archives fits well into a test tool, so I hope AQA will improve on this so I don't depend on WinRar in the tests.
Also, I must admit that I am not very familiar with .Net / C# / VBScript but rather Delphi Script 😉
Thanks again for sharing your ideas,