【问题标题】:Delete files older than so many days in multiple zips删除多个 zip 中超过这么多天的文件
【发布时间】:2012-07-30 16:08:26
【问题描述】:

救命!

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

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

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

干杯

【问题讨论】:

  • 澄清一下,您不想删除 ZIP 文件。相反,您想删除 ZIP 中超过 584 天的日志文件,对吧?
  • 这是正确的 keith - 谢谢

标签: windows iis powershell


【解决方案1】:

使用 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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多