Skip to content

Instantly share code, notes, and snippets.

@ebith
Last active October 1, 2019 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebith/def83fd8c7d9a033d4527372418b1691 to your computer and use it in GitHub Desktop.
Save ebith/def83fd8c7d9a033d4527372418b1691 to your computer and use it in GitHub Desktop.
7-Zip付属の7zG.exeで二重フォルダを防ぎ賢く展開するWSH JScript
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