ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Finished Programs

Directory Squasher: taking the in out of inconsistency


ZIP files come in two varieties, oddly mirroring the users which create them...

The first variety has the files directly in the root of the zip files. These are created by users who select multiple files and create an archive out of them.

The second variety has the files stuck inside a directory that is in the root of the archive. This was accomplished by selecting a single directory and then creating an archive out of that.

(OK, there's far more varieties, but they are just worse and arguably insane variations of the second variety...)

When you extract the first kind, you'll want to extract it to a subdirectory, usually using an option like 'Extract to MyZipFile\'. Otherwise, you get the crap stuck in the middle of all your other files, which is really annoying!

When you extract the second kind, you want to extract it to the same directory, because otherwise you've got a wonderful beginning with matroshka dolls: a single directory inside a directory. It's just annoying.

And unless you peek inside a zip (as opposed to rightclicking and just extracting like I tend to do) there's no other option but to guess... and since the least damaging option is to extract into a new directory, you will thus end up with the worst-case scenario of the second variety.

So what is this little script about?!

Basically, I had to extract about a thousand zip files... and they were a mix of both varieties. Fixing the nested directories manually... yeah. I wasn't going to put myself through that pain. So instead I wrote a pair of batch files.

It's just a simple script, but since I happened to need to do a lot of it, I figured I'd automate it and then share it with all of you.

Squash-All: Squashes all subdirectories of the current directory.
Squash-Directory: Squashes a given directory.

There's no real special features save for the fact it avoids conflicts where you have a folder 'test' inside a folder 'test' which could cause issues whilst moving the files up a level. Other than that, it's just a batch file.

Have fun? :-)

I've had a look at it, and it looks quite impressive :Thmbsup:
Did a lot of Windows (and DOS) scripting using batchfiles over the years, so I've seen quite some anomalies during testing, and I can only assume you've seen a few while working on this ;D
One of the reasons I love bash/shell scripting: it just works :up:

Eh, this one was pretty simple. Didn't have to fuss much with it, but that's because I did some other batch files in the past month which were absolute nightmares. (I really need to learn PS at some point, but it's so much easier to just work with something I 'get' rather than get lost in an ecosystem and syntax where I'm not even sure how to do something trivial, nevermind combine the complicated stuff I want done!)

Compared to programs borking over unicode characters, delayed variable expansion in batch files and more of such silliness, this was pretty easy. Most of my mind went into the 'ok, I've got A inside A, how do I fix this in a generic way that is fool-proof and does not involve copying files, especially not across drive boundaries' dilemma...

NANY 2018 App of the Year! :Thmbsup:


[0] Message Index

Go to full version