這是66%的解決方案(午餐結束)。我不能讓本土拉鍊使用PowerShell的工作,但如果你有安裝PowerShell的社區擴展,應該換出拉鍊通話瞬間 How to create a zip archive with PowerShell?
# purloined from http://blogs.inetium.com/blogs/mhodnick/archive/2006/08/07/295.aspx
# I am not smart enough to make it work. Creates an empty .zip file for me
Function ZipIt
{
param
(
[string]$path
, [string]$files
)
if (-not $path.EndsWith('.zip')) {$path += '.zip'}
if (-not (test-path $path)) {
set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}
$zipFile = (new-object -com shell.application).NameSpace($path)
#$files | foreach {$zipfile.CopyHere($_.fullname)}
foreach($file in $files)
{
$zipfile.CopyHere($file)
}
}
# this script is reponsible for enumerating subfolders
# for each file it finds, it will test the age on it
# returns an array of all the files meeting criteria
Function Walk-SubFolder
{
param
(
[string]$RootFolder
)
$searchPattern = "*.*"
$maxAge = 90
$now = Get-Date
# receiver for the files
[string[]] $agedOutFileList = @()
foreach($file in [System.IO.Directory]::GetFiles($RootFolder, $searchPattern, [System.IO.SearchOption]::AllDirectories))
{
# test whether the file meets the age criteria
$age = [System.IO.File]::GetLastWriteTime($file)
$days = ($now - $age).Days
if (($now - $age).Days -ge $maxAge)
{
# this needs to be archived
Write-Host("$file is aged $days days")
$agedOutFileList = $agedOutFileList + $file
}
}
return $agedOutFileList
}
Function PurgeFiles
{
param
(
$fileList
)
foreach($file in $fileList)
{
# this should be in a try/catch block, etc, etc
[System.IO.File]::Delete($file)
}
}
$sourceFolder = "C:\tmp\so"
$zipFile = "C:\tmp\so.zip"
$oldFiles = Walk-SubFolder $sourceFolder
ZipIt $zipFile $oldFiles
#This is commented out as the zip process is not working as expected
#PurgeFiles $oldFiles
我去看看我可以工作它稍後會按預期的方式讓zip工作。
在\\服務器\記錄有子目錄。這些子目錄將包含不以.zip結尾的文件。該過程應標識過去90天內尚未(創建/修改/訪問?)的所有文件,並將其放入現有目錄結構中的.zip文件中。創建存檔文件後,應該刪除那些相同的文件。準確? – billinkc 2012-01-11 18:17:59
@billinkc - 現在你提到它了,在'\\ server \ oldlogs'目錄中創建zip文件似乎更簡單。我想結束一天中命名的zip文件,其中包含該日期上次修改的文件。那麼是的,一旦他們被壓縮,他們應該被刪除。我會更新這個問題。謝謝。 – 2012-01-11 18:32:40
爲什麼你使用powershell標籤?你需要關於問題或功能腳本的意見嗎? – mjsr 2012-01-11 19:16:36