Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • July 22, 2017, 09:49:55 PM
  • Proudly celebrating 10 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 507 times)

worstje

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 580
    • View Profile
    • Donate to Member
Directory Squasher: taking the in out of inconsistency
« on: May 02, 2017, 01:14:11 PM »
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: 2,959
    • View Profile
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #1 on: May 02, 2017, 02:22:04 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: 580
    • View Profile
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #2 on: May 02, 2017, 03:15:11 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: 7,971
    • View Profile
    • Donate to Member
Re: Directory Squasher: taking the in out of inconsistency
« Reply #3 on: May 02, 2017, 04:14:16 PM »
NANY 2018 App of the Year! :Thmbsup: