Skip to content

Instantly share code, notes, and snippets.

@ebith
Last active Oct 1, 2019
Embed
What would you like to do?
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