-gt是大于,-ge是大于或等于,其他看帮助。
如果PSIsContainer属性为真那意味着处理的是文件夹而不是文件。
-Force是包括只读、隐藏等系统文件,用了它之后最好用-ErrorAction。
-ErrorAction:SilentlyContinue作用是不显示错误继续执行脚本,比如递归时遇到
System Volume Information等无权限进入的目录就会出错。
查找指定日期前创建的文件:
Get-ChildItem -Path D:test -Force -Recurse -ErrorAction:SilentlyContinue | `
Where-Object -FilterScript {($_.CreationTime -gt "2011-01-01") -and `
($_.PsISContainer -ne $True)} | Select-Object FullName
查找指定日期前修改的文件:
Get-ChildItem -Path D:test -Force -Recurse -ErrorAction:SilentlyContinue | `
Where-Object -FilterScript {($_.LastWriteTime -gt "2011-01-01") -and `
($_.PsISContainer -ne $True)} | Select-Object FullName
如果要删除,Select-Object FullName改成Remove-Item -Force
指定日期的用批处理还是很方便,如果要指定删除N天前的旧文件就麻烦了点,
下面的示例是用bat删除指定日期修改过的文件。注意是修改,不是创建,只
有dir /tc才能查看到文件创建时间,默认dir都是dir /tw
发信人: nwn (Lie), 信区: DOS
标 题: Re: (for命令)批量删除某一时间段内创建的文件?
发信站: 水木社区 (Sat Jun 7 08:39:39 2008), 站内
@echo off cd /d 你的目录 for %%f in (*) do if "%%~tf" gtr "2008-04-01" del "%%f"
如果要包含子目录,使用 for /r . %%f in ....
【 在 justzhou (玉树临风) 的大作中提到: 】
: 比如要删除某目录下2008-04-01后创建的所有的文件。。










