You are not logged in.
I'm writing a script that decompresses zipped/rared files.
The zips typically have content in a one directory or not contained in a directory.
Is there a way to see if the unzip process created a directory and move into it or if one wasn't created to operate on the files extracted in the PWD?
So far the rar files have only had data that gets extracted to PWD, but if I see some with files in directories I'd like for a solution that might work in that case as well.
Offline
Would zipinfo' help? It lists zip archive files in a format similar to 'ls -l'.
I only tried this on two zipfiles, and I'm concerned about how foolproof this may or may not be.
Zipinfo lists the files in the opposite order that they were placed into the zipfile, I think. If the first file placed into the zip was the parent directory, and so contains all the other files, the listing will be something like that shown below, with the container directory always on the next-to-last line of zipinfo's output:
...
-rw-a-- 2.0 fat 1057 tx defX 09-Nov-12 17:56 examples/README.txt
drwx--- 2.0 fat 0 bx stor 09-Nov-12 16:48 examples/
42 files, 508682 bytes uncompressed, 133398 bytes compressed: 73.8%
So one would have to test if the next-to-last line of zipinfo's output begins with 'd' (directory) or '-' (regular file).
Off the top of my head, with not-so great command-line skills, I came up with:
zipinfo example.zip | tail -n 2 | grep '^d'
Offline
Yeah thats a possibility. I know that you can also do
unzip -l filename.zip
and it'll print a listing as well.
I'm really trying to understand how CBR/CBZ comic readers do it as that is the target zip archive that I'm trying to extract and modify.
I'm trying to look at some code now.
And a python/perl solution also would also be a possibility if anyone knows how to do that as well.
Offline