1

我有两个命令。第一个工作正常,但第二个不行。我不断收到错误消息“无法找到...”,即使该文件确实存在于那里。为什么 del 不起作用,但 echo 起作用?我正在尝试删除该路径中扩展名为 .jpg 的所有文件。

forfiles /p "C:\Users\hi\Desktop\test" /m *.jpg /d -1 /c "cmd /c echo @path @fdate"
pause

forfiles /p "C:\Users\hi\Desktop\test" /m *.jpg /d -1 /c "cmd /c del @path @srchmask"
pause
4

1 回答 1

3

为什么不是del工作,而是echo意志?

echo只会输出你告诉它的任何东西。

forfiles /p "C:\Users\hi\Desktop\test" /m *.jpg /d -1 /c "cmd /c del @path @srchmask"

上述命令不正确。没有@srchmask为 to 命令定义的“命令变量” forfiles

Command Variables:
  @file    The name of the file.
  @fname   The file name without extension.                
  @ext     Only the extension of the file.                  
  @path    Full path of the file.
  @relpath Relative path of the file.          
  @isdir   Returns "TRUE" if a file type is a directory,
           and "FALSE" for files.
  @fsize   Size of the file in bytes.
  @fdate   Last modified date of the file.
  @ftime   Last modified time of the file.

文件

你已经/m *.jpg为你的命令指定了一个“搜索掩码” forfiles,所以我不确定你打算用@srchmask. 你可以试试直接删掉...

您还应该阅读del的语法,以防您需要其他选项而不是@srchmask...


延伸阅读

  • Windows CMD 命令行的 AZ 索引- 与 Windows cmd 行相关的所有内容的绝佳参考。
  • del - 删除一个或多个文件。
  • forfiles - 选择一个文件(或一组文件)并对每个文件执行一个命令。批量处理。
于 2016-07-26T20:27:17.750 回答