PowerShellでZIP圧縮する。
VB.NETからPowerShellに焼き直し。
MakeZIP.ps1 ZIPファイル ファイル...
if($args.length -lt 2){
write-output "Arguments Missing.";
write-output "Usage: MakeZIP.PS1 ZIPfile files...";
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])){
set-content $args[0] ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18));
}
$shell=new-object -com shell.application;
$zFolder = $Shell.NameSpace([System.IO.Path]::GetFullPath($args[0]));
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
for($k=1;$k -lt $args.length;$k++){
$File=[System.IO.Path]::GetFileName($args[$k]);
$sFolderItem=$Shell.NameSpace([System.IO.Path]::GetFullPath($args[$k]+"\..")).ParseName($File);
if(-not $sFolderItem){
write-output ("File Not Found. - " + $args[$k]);
break;
}
for($answer=[System.Windows.Forms.DialogResult]::Yes;$answer -eq [System.Windows.Forms.DialogResult]::Yes;){
$zFolderItem=$zFolder.ParseName($File);
if(-not $zFolderItem){
$Count=$zFolder.Items().Count;
$zFolder.CopyHere($sFolderItem);
while($zFolder.Items().Count -le $Count){
Start-sleep -milliseconds 1000;
}
break;
}else{
$answer = [System.Windows.Forms.MessageBox]::Show("このフォルダには既に次のファイルが存在します:`n`n" + '"' + $File + '"' +"`n`n既存のファイルと置き換えますか?", "ファイル置換の確認", [System.Windows.Forms.MessageBoxButtons]::YesNoCancel, [System.Windows.Forms.MessageBoxIcon]::Question)
if($answer -eq [System.Windows.Forms.DialogResult]::Yes){$zFolderItem.InvokeVerb("delete");}
}
}
if($answer -eq [System.Windows.Forms.DialogResult]::Cancel){break;}
}
« VB.NETで、RunningObjectTable(ROT)の表示名を列挙する、コマンドを作る。 | トップページ | スクリプトを使わずに、関連付けで、Excelファイルをコマンドラインで印刷する。 »