这是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