Hey, everyone! I’m quite new to PowerShell, but wanted to share a new script I’m working on. I’ve been reverse engineering video games for years, but have recently wanted to start creating my own tools. One such tool is a script that would do a couple of specific things for me:
1. Allow me to specify a directory with which to scan (including all child directories) for zip-compressed files, then extract all the archives that are found to directories of the file names found.
2. Allow me to specify a particular file to extract to a directory of my choice (in the event that scanning finds multiple files but I only want to extract one of them, etc.).
For my use case, I specify a game directory in search of assets that are zip-compressed. This is common, but often times the files are named with some other custom extension instead of .zip, so for every file scanned, I have PowerShell checking the first 4 bytes for the magic number. If the first two bytes are PK (0x50 and 0x4B), then the file is noted as a positive result.
I make use of Expand-Archive for the actual extraction, but because it only works on files with a .zip extension, I temporarily rename positive results with .zip on the end prior to extraction, then rename the file(s) back afterward. There’s likely a better way to go about this, but this is my solution for the time being.
Anyway, there are a few kinks I’m still working out before I would consider it MVP-status (that is, minimum viable product), but once those things are ironed out, I have plans to greatly extend this script’s purpose and functionality.
Finally, I know the code is probably ugly and there are countless things I could be doing better, so I welcome any and all feedback regarding improvements–whether performance related or otherwise. And in the event that someone out there finds this script useful, well I think that would just be the bee’s knees. =)
Note: I still have to build in logic for handling when file names are too long to be created/extracted, so if you try using this, consider extracting to a new directory in root. I’ve suppressed all PowerShell error messages throughout this script.
Link on Github: extractifyr
submitted by /u/Sn34kyMofo
[link] [comments]
The post extractifyr: Scan for zip archives (regardless of file extension) and optionally extract them. appeared first on How to Code .NET.