繁体   English   中英

提示或PS命令删除x天之前的文件夹

[英]prompt or PS command to delete folders older than x days

我正在使用inno安装程序构建安装程序,我想使用单个命令添加计划任务以清理X天之前的日志文件夹。 我正在搜索使powershell或提示命令的示例,但没有任何效果。

你能帮我找到最好的方法吗?

谢谢

我没有太多时间来研究此问题,但是如果您想在连续覆盖特定时间范围的文件夹位置内搜索文件,可以使用以下脚本;

while($true){

    # You may want to adjust these

    $fullPath = "C:\temp\_Patches\Java\Files\x86\Source"
    $numdays = 5
    $numhours = 10
    $nummins = 5

    function ShowOldFiles($path, $days, $hours, $mins)
    {
        $files = @(get-childitem $path -include *.* -recurse | where {($_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins)) -and ($_.psIsContainer -eq $false)})
    if ($files -ne $NULL)
    {
        for ($idx = 0; $idx -lt $files.Length; $idx++)
        {
            $file = $files[$idx]
            write-host ("Old: " + $file.Name) -Foregroundcolor Red
            Start-Sleep -s 10
        }
    }
}

ShowOldFiles $fullPath $numdays $numhours $nummins
}

您只需要将此脚本添加到启动文件夹并更改值(例如,EG文件路径,文件使用期限,睡眠)。 您也可以将数据附加到文本文件。

我从以下文章开始: 如何使用PowerShell检查文件是否早于特定时间?

谢谢,

卡尔文

编辑:格式化

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM