[英]Batch - Delete a specific file with forfiles
I want to do echo
only checking the date from one file with forfiles
: 我只想用
forfiles
echo
一个文件中的日期:
forfiles /m "C:\Backups\TEST.bak" /c "cmd /c echo test" /d -1
But it returns me an error : 但是它返回了一个错误 :
The System cannot find the file specified.
该系统找不到指定的文件。
And that file it exists and the directory is correct. 并且该文件存在并且目录正确。
If use forfiles
in the same directory (without file) it works fine: 如果在同一目录中使用
forfiles
(不带文件),则可以正常工作:
forfiles /p "C:\Backups" /c "cmd /c echo test" /d -1
What am I doing wrong? 我究竟做错了什么?
The problem is that forfiles requires a directory as parameter. 问题在于forfiles需要目录作为参数。 You are giving it a file instead.
您正在给它一个文件 。 This won't work.
这行不通。
Instead you should do this: 相反,您应该这样做:
FOR %%a in (C:\Backups\TEST.bak) DO SET FileDate=%~ta
This will store the file's modifed date in %FileDate%
. 这会将文件的修改日期存储在
%FileDate%
。
forfiles /p "c:\Backups" /m "test.bak" /d -1 /c "cmd /c echo @fdate @ftime"
/p
needs a folder to start searching /p
需要一个文件夹才能开始搜索
/m
needs a file mask to indicate what to search /m
需要文件掩码以指示要搜索的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.