windows - 提示或 PS 命令删除超过 x 天的文件夹
问题描述
我正在使用 inno setup 构建设置,我想添加计划任务以使用单个命令清理早于 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 检查文件是否早于某个时间?
谢谢,
卡尔文
编辑:格式化
推荐阅读
- html - HTML如何在新行上显示列表中的元素
- python - 通过来自另一个字典的嵌套 id 过滤字典列表
- php - Wordpress Loop - 不返回特定类别的项目
- capistrano - 使用 Capistrano 设置全新的 Rails 应用程序部署。删除了我的部署目录并重新部署,现在日志不起作用
- java - 查找n个数组树中具有相同名称的节点的所有子节点和子节点
- c# - 绑定到 actualWidth 不起作用,尽管它在设计器中起作用;wpf
- html - 嵌套的弹性列可防止子级限制到最大高度
- scrapy - Scrapy:展开元素后信息仅在文本中可见
- python - 为什么列表中的所有元素都没有被删除?
- python - 在叶传单中覆盖本地 .TIFF 文件?