topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 9:16 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Directory Squasher: taking the in out of inconsistency  (Read 7895 times)

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 588
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
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? :-)


Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #1 on: May 02, 2017, 02:22 PM »
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:

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 588
  • The Gent with the White Hat
    • View Profile
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #2 on: May 02, 2017, 03:15 PM »
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...

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,747
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #3 on: May 02, 2017, 04:14 PM »
NANY 2018 App of the Year! :Thmbsup: