PowerShellでZIP展開する。
IE7に対応。
ExtractZIP.PS1 ZIPファイル [展開先フォルダ\][ファイル]...
if($args.length -lt 1){
write-output "Arguments Missing.";
write-output "Usage: ExtractZIP.PS1 ZIPfile [folder\][file]...";
return;
}
if([System.IO.Path]::GetExtension($args[0]) -ne ".zip"){
write-output ("Invalid Extension Name - " + $args[0]);
return;
}
if(-not [System.IO.File]::Exists($args[0])){
write-output ("File Not Found. - " + $args[0]);
return;
}
[void][reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic");
#IE7以降も可
$Shell=new-object -com Shell.Application;
$ZIPfile=$Shell.NameSpace([System.IO.Path]::GetFullPath($args[0])).Self.Path;
$Shell.ShellExecute("explorer.exe",$ZIPfile,$null,$null,0);
while($true){
foreach($ie in $Shell.Windows()){
if($ie.Visible){}
elseif([Microsoft.VisualBasic.Information]::TypeName($ie.Document) -like "IShellFolderViewDual*"){
if($ie.Document.Folder.Self.Path -eq $ZIPfile){break;}
}
$ie=$null;
}
if($ie){break;}
Start-sleep -milliseconds 100;
}
#$ie=new-object -com InternetExplorer.Application; #IE7以降ダメ
#$ie=[Microsoft.VisualBasic.Interaction]::GetObject("new:{C08AFD90-F2A1-11D1-8455-00A0C91F3880}"); #IE7以降も可
#$ie.Navigate([System.IO.Path]::GetFullPath($args[0]));
while($ie.Busy -or ($ie.ReadyState -ne 4)){
Start-sleep -milliseconds 100;
}
$Shell=$ie.Document.Application;
$zFolder=$ie.Document.Folder;
if($args.length -eq 1){
$dFolder=$Shell.NameSpace(([System.Environment]::CurrentDirectory));
$dFolder.CopyHere(($zFolder.Items()));
}elseif(($arg.length -eq 2) -and $args[1].EndsWith("\")){
if(-not [System.IO.Directory]::Exists($args[1])){
write-output ("Folder Not Found. - " + $args[1]);
return;
}
$dFolder=$Shell.NameSpace([System.IO.Path]::GetFullPath($args[1]));
$dFolder.CopyHere(($zFolder.Items()));
}else{
for($k=1;$k -lt $args.length;$k++){
$File=[System.IO.Path]::GetFileName($args[$k]);
$Folder=[System.IO.Path]::GetDirectoryName($args[$k]);
if($Folder -ne ""){
if(-not [System.IO.Directory]::Exists($Folder)){
write-output ("Folder Not Found. - " + $Folder);
break;
}
}
$dFolder=$Shell.NameSpace([System.IO.Path]::GetFullPath($args[$k]+"\.."));
$zFolderItem=$zFolder.ParseName($File);
if(-not $zFolderItem){
write-output ("File Not Found. - " + $File);
break;
}
$dFolder.CopyHere($zFolderItem);
}
}
$ie.Quit();
« VB.NETでZIP圧縮コマンドを作る。(その2) | トップページ | PowerShellでZIP圧縮する。(その2) »