Created
January 25, 2014 17:07
-
-
Save meganehouser/8619643 to your computer and use it in GitHub Desktop.
頼まれたやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 使い方 | |
### 1. PowerShellを起動する | |
### 2. PowerShell 実行権限の変更(最初の一回のみ実行) | |
### Set-ExecutionPolicy RemoteSigned | |
### 3. 7z をインストール(インストールしたフォルダ内に7z.exeがある) | |
### http://sevenzip.sourceforge.jp/download.html | |
### 4. このスクリプトをCopyZip.ps1というファイル名で実行 | |
### 5. コピー元のフォルダパス、コピー先・ZIPファイル作成先のフォルダパス、7z.exeのパスを書き換える | |
### 6. PowerShellでカレントディレクトリをCopyZip.ps1を置いたディレクトリに移動 | |
### 7. 以下のコマンドを実行 | |
### .\CopyZip.ps1 | |
# コピー元のフォルダパス | |
$sourceFolder = 'C:\source' | |
# コピー先・ZIPファイル作成先のフォルダパス | |
$destFolder = 'C:\dest' | |
# 7z.exeのパス | |
$zipExe = 'C:\Program Files (x86)\7-Zip\7z.exe' | |
# コピー先一時フォルダ | |
$tempFolder = Join-Path $destFolder $(Get-Date).ToString("yyyyMMdd") | |
New-Item -Path $tempFolder -ItemType Directory -Force | |
# コピー元からコピー先にコピーを行う | |
Copy-Item $sourceFolder $tempFolder -recurse -Force | |
# コピー先から空のフォルダを削除する | |
Get-ChildItem -Path $tempFolder -Recurse | Where-Object {$_.PSIsContainer -and !$_.GetFiles().Count -and !$_.GetDirectories().Count} | Remove-Item -Force | |
# ZIP圧縮 | |
$destZipFolder = Join-Path $destFolder ($(Get-Date).ToString("yyyyMMdd") + "_" + (Split-Path $sourceFolder -Leaf)) | |
cmd /c $zipExe a -tzip $destZipFolder $tempFolder | |
# 一時フォルダ削除 | |
Remove-Item -Path $tempFolder -Recurse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment