Batch - forfiles 命令详解
forfiles 命令详解
C:\Users\cuixunxu>forfiles /? FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D [+ | -] {MM/dd/yyyy | dd}] Description: Selects a file (or set of files) and executes a command on that file. This is helpful for batch jobs. Parameter List: /P pathname Indicates the path to start searching. The default folder is the current working directory (.).表示开始搜索的路径。默认文件夹是当前工作的目录 (.) /M searchmask Searches files according to a searchmask. The default searchmask is '*' .根据搜索掩码搜索文件。默认搜索掩码是 '*' /S Instructs forfiles to recurse into subdirectories. Like "DIR /S".指导 forfiles 递归到子目录。像 "DIR /S"。 /C command Indicates the command to execute for each file. Command strings should be wrapped in double quotes. 表示为每个文件执行的命令。命令字符串应该用双引号括起来。 The default command is "cmd /c echo @file". 默认的command是“cmd /c echo @file” The following variables can be used in the command string: @file - returns the name of the file.返回文件名 @fname - returns the file name without extension.返回不带扩展名的文件名 @ext - returns only the extension of the file.只返回文件的扩展 @path - returns the full path of the file.返回文件的完整路径 @relpath - returns the relative path of the file.返回文件的相对路径 @isdir - returns "TRUE" if a file type is 如果文件类型是目录,返回true a directory, and "FALSE" for files.如果是文件,返回false @fsize - returns the size of the file in bytes.以字节为单位返回文件大小 @fdate - returns the last modified date of the file.返回文件上一次修改的日期 @ftime - returns the last modified time of the file.返回文件上一次修改的时间 To include special characters in the command line, use the hexadecimal code for the character in 0xHH format (ex. 0x09 for tab). Internal CMD.exe commands should be preceded with "cmd /c". /D date Selects files with a last modified date greater than or equal to (+), or less than or equal to (-), the specified date using the "MM/dd/yyyy" format; or selects files with a last modified date greater than or equal to (+) the current date plus "dd" days, or less than or equal to (-) the current date minus "dd" days. A valid "dd" number of days can be any number in the range of 0 - 32768. "+" is taken as default sign if not specified. 指定日期,有绝对日期和相对日期, 此处-7指当前日期 的7天前 /? Displays this help message.显示此帮助消息 Examples: FORFILES /? FORFILES FORFILES /P C:\WINDOWS /S /M DNS*.* FORFILES /S /M *.txt /C "cmd /c type @file | more" FORFILES /P C:\ /S /M *.bat FORFILES /D -30 /M *.exe /C "cmd /c echo @path 0x09 was changed 30 days ago" FORFILES /D 01/01/2001 /C "cmd /c echo @fname is new since Jan 1st 2001" FORFILES /D +9/27/2019 /C "cmd /c echo @fname is new today" FORFILES /M *.exe /D +1 FORFILES /S /M *.doc /C "cmd /c echo @fsize" FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"
注意:
这些命令是等价的: /S 等同于 -s, /M 等同于 -m
分类:
Batch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?