Last active
October 1, 2019 11:20
-
-
Save ebith/def83fd8c7d9a033d4527372418b1691 to your computer and use it in GitHub Desktop.
7-Zip付属の7zG.exeで二重フォルダを防ぎ賢く展開するWSH JScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wshell = new ActiveXObject('WScript.Shell'); | |
var fso = new ActiveXObject( 'Scripting.FileSystemObject'); | |
var archivePath = WScript.arguments(0); | |
var dirPath = wshell.currentDirectory + '/' + fso.getBaseName(archivePath); | |
var process = wshell.Exec('"C:/Program Files/7-zip/7zG.exe" x "' + archivePath + '" -aou -spe -o"' + dirPath + '"'); | |
while (process.status !== 1) { | |
WScript.sleep(10); | |
} | |
var dir = fso.getFolder(dirPath); | |
if (dir.files.count + dir.subfolders.count === 1) { | |
var collection = dir.files.count > 0 ? dir.files : dir.subfolders; | |
(new Enumerator(collection)).item().move(fso.getParentFolderName(dir) + '/'); | |
fso.deleteFolder(dir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment