【发布时间】:2012-09-10 14:00:00
【问题描述】:
我的问题在于 Powershell。 我有一个很大的文件夹。 Insider 大约有 1 600 000 个子文件夹。 我的任务是删除它们下面所有超过 6 个月的空文件夹或文件。 我用 foreach 写了一个循环,但是在 powershell 开始之前需要很长时间 ->
...
foreach ($item in Get-ChildItem -Path $rootPath -recurse -force | Where-Object -FilterScript { $_.LastWriteTime -lt $date })
{
# here comes a script which will erase the file when its older than 6 months
# here comes a script which will erase the folder if it's a folder AND does not have child items of its own
...
问题:我的内存已满(4GB),我无法正常工作了。 我的猜测:powershell 会加载所有 1 600 000 个文件夹,然后才开始过滤它们。
有没有可能防止这种情况发生?
【问题讨论】:
标签: memory powershell foreach internal subdirectory