如何在命令行中删除超过 7 天的文件夹和文件?

Mah*_*adi 4 windows command-line

我想使用命令行删除文件夹及其文件创建时间超过 7 天。

小智 12

*尼克斯

如果您正在使用 *nix 并找到可用的,这应该可以解决问题:

find /the/directory/containing/files/to/delete -mtime +7 -exec rm -r {} \;
Run Code Online (Sandbox Code Playgroud)

该标志-mtime是检查找到的文件的修改时间戳。如果它在上面7*24h之前,
它将执行rm /path/to/file

从联机帮助页 find

-mtime n  
    File's  data was last modified n*24 hours ago.  See the comments  
    for -atime to understand how rounding affects the interpretation  
    of file modification times.  
Run Code Online (Sandbox Code Playgroud)

WINDOWS XP 和 VISTA

我从来没有在 Windows 上工作过,尽管我很想知道在 MS-DOS 环境中什么命令与上面的命令等效。我在 stackoverflow 上发现批处理文件可以删除超过 N 天的文件

相关命令(从先前链接的线程复制+粘贴):

forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"
Run Code Online (Sandbox Code Playgroud)

WINDOWS 7的

语法发生了一些变化,因此更新的命令是

forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"
Run Code Online (Sandbox Code Playgroud)