Skip to content

Instantly share code, notes, and snippets.

Last active October 14, 2016 00:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save GNQG/4e505acb05a9f76e9b0ce7dc5dae6695 to your computer and use it in GitHub Desktop.
Extract BMS archives with appropriate directory structure
function Get-CommonDirectoryPath($paths){
# original:
0{return $null}
for($r = 0; $r -lt $s.Count-1; $r++) {
return $v
$p=New-Object System.Collections.ArrayList
for($i=0; $i -lt $paths.Count; $i++) {
$c = -1
$found = $false
do {
$t = $p[0][++$c]
for($r = 1; $r -lt $p.Count; $r++) {
if ($t -ne $p[$r][$c]) {$found=$true; break }
} until ($found)
for($i=0; $i -lt $c; $i++) {$s += "/"+$p[0][$i]}
return $s.TrimStart("/")
function Extract-BmsArchives(){
$archives=@(Get-ChildItem -Name *.zip,*.rar,*.7z)
foreach($arc in $archives){
$dirs=New-Object System.Collections.ArrayList
$files=New-Object System.Collections.ArrayList
$bmsfiles=New-Object System.Collections.ArrayList
[string]::Join("`n",@(7z l $arc)),$reg
) | foreach{
if ($property.StartsWith('D')){
if ($path -notmatch $reg_exc_dir){
if ($path -notmatch $reg_exc_file){
if ($path -match $reg_bms){
if($com_pre -ne $com_pre_bms){
"***Skipped: $arc***"
foreach($entry in $files){
if (-not $dirdict.ContainsKey($extpath)){
$dirdict[$extpath]=New-Object System.Collections.ArrayList
if ($args -contains "-DirNameMajored"){
if (-not $dirname){
$dirname=[System.IO.Path]::GetFileNameWithoutExtension($arc).TrimEnd(". ")
foreach($childdir in $dirdict.Keys){
[String]::Join("`n",$dirdict["$childdir"].ToArray()) | Set-Content -path tmpfilelist.dat -encoding UTF8
"7z e -aos -o""$dirname/$childdir"" ""$arc"" `@tmpfilelist.dat"
$dummy=(7z e -aos -o"$dirname/$childdir" "$arc" `@tmpfilelist.dat)
if ($LASTEXITCOD -gt 0){
"7z failed with error code $LASTEXITCODE"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment