嘿家伙,所以我写了这个脚本来自动删除指定文件夹中的文件。使用powershell删除旧文件
$oldTime = [int]25 # 0 days
$old2Time = [int] 10
foreach ($path in "C:\Test") {
Write-Host "Trying to delete files older than days, in the folder $path" -
ForegroundColor Green
# Write information of what it is about to do
Get-ChildItem $path -Recurse -Include "*.txt", "*.docx", "*.xlsx" #| WHERE
{($_.CreationTime -le $(Get-Date).AddDays($oldTime))} #| Remove-Item -Recurse -Force}
if ($_.CreationTime -le $(Get-Date).AddDays(-$oldTime))
{
Remove-Item -Recurse -Force
}
elseif ($_.CreationTime -le $(Get-Date).AddDays(-$old2Time))
{
Remove-Item -Recurse -Force
}
}
# deleting the old files
,当我有它只是检查单的时间和删除任何旧的工作之前。但是现在我想要检查是否存在超过一定天数的任何文件,然后删除它们。如果不是,则检查比另一天多的时间。但是当我运行它,我得到“小命令删除,项目在命令管道位置以下参数1个 供应值: 路径[0]:”
有谁知道什么即时做错了什么?谢谢
ahhh非常感谢你!我现在看到你做了什么。没有意识到powershell是这个复杂的。再次感谢! – user2725926