在多个拉链中删除超过这么多天的文件

时间:2012-07-30 16:08:27

标签: windows iis powershell

帮助!

我需要扫描一个包含200gb压缩.log日志文件的文件夹,并删除超过584天的所有文件。

我找到了这个,并在那里留了回复,但如果有人可以在此期间提供帮助,那么谢谢

http://social.technet.microsoft.com/Forums/en/ITCG/thread/793118fb-8345-4711-9710-9c3e485e6d89?prof=required

干杯

1 个答案:

答案 0 :(得分:0)

使用SevenZipSharp。首先备份所有重要数据:)

确保阅读并更改任何无意义的路径等。

[Reflection.Assembly]::LoadFile("c:\lib\SevenZipSharp.dll")
[SevenZip.SevenZipExtractor]::SetLibraryPath("c:\lib\7z.dll")
$zipFiles = Get-ChildItem D:\zips\ -Filter "*.zip"
$oldDate = (get-date).AddDays(-584)

$zipFiles | % {
    $compressor = [SevenZip.SevenZipCompressor]("C:\")
    $compressor.ArchiveFormat = "zip"
    $extractor = [SevenZip.SevenZipExtractor]($_.FullName)
    $object = New-Object 'system.collections.generic.dictionary[int,string]'
    $extractor.ArchiveFileData | %{
        if ($_.LastWriteTime -lt $oldDate){
            #null index deletes the file
            $object.add($_.Index,"")
        }
        else {
            $object.add($_.Index,$_.FileName)
        }
    }
    $compressor.ModifyArchive($_.FullName,$object)
}