Skip to content

Instantly share code, notes, and snippets.

@notogawa
Created July 8, 2012 17:00
Show Gist options
  • Save notogawa/3071776 to your computer and use it in GitHub Desktop.
Save notogawa/3071776 to your computer and use it in GitHub Desktop.
コマンドプロンプト起点(バッチファイル)で,PowerShellはアリ,PowerShellスクリプトファイル不可,サードパーティ不可という制約上でzip圧縮するには?
@echo off
REM どうすんだこれ;;
REM for /f "delims=" %%i in ( %~1 ) do (
REM if "%%i" == "@echo off" (
REM echo @echo on
REM ) else (
REM echo %%i
REM )
REM )
echo.^
function New-Zip {^
param([string]$zipfilename);^
set-content $zipfilename (\"PK\" + [char]5 + [char]6 + (\"$([char]0)\" * 18));^
(dir $zipfilename).IsReadOnly = $false;^
};^
function Add-Zip {^
param([string]$zipfilename);^
if(-not (test-path($zipfilename))) {^
set-content $zipfilename (\"PK\" + [char]5 + [char]6 + (\"$([char]0)\" * 18));^
(dir $zipfilename).IsReadOnly = $false;^
}^
$shellApplication = new-object -com shell.application;^
$zipPackage = $shellApplication.NameSpace($zipfilename);^
foreach($file in $input) {^
$zipPackage.CopyHere($file.FullName);^
Start-sleep -milliseconds 500;^
}^
};^
new-zip test.zip;^
for /f "delims=" %%i in ('findstr .*') do @(
powershell -Command "%%i"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment