Batch file 批处理文件Del-找不到

Batch file 批处理文件Del-找不到,batch-file,del,Batch File,Del,我有两条命令。第一个很好用,但第二个不行。我不断收到错误,“找不到…”,即使文件确实存在。为什么del不起作用,但回声会起作用?我正在尝试删除该路径中扩展名为.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 @

我有两条命令。第一个很好用,但第二个不行。我不断收到错误,“找不到…”,即使文件确实存在。为什么del不起作用,但回声会起作用?我正在尝试删除该路径中扩展名为.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
为什么
del
不起作用,而
echo
会起作用?
echo
将只输出您告诉它的任何内容

forfiles /p "C:\Users\hi\Desktop\test" /m *.jpg /d -1 /c "cmd /c del @path @srchmask"
上述命令不正确。没有为to
forfiles
命令定义名为
@srchmask
的“命令变量”:

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
命令的“searchmask”,因此我不确定您打算对
@srchmask
执行什么操作。你可以试着移除它

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


进一步阅读
  • -对于所有与Windows命令行相关的内容都是一个很好的参考
  • -删除一个或多个文件
  • -选择一个文件(或一组文件)并对每个文件执行命令。批处理

对于@srchmask,它的目的是说类似于转到该路径并用ext.jpg删除那里的任何文件。这是我最初使用它的方式,但仍然得到“找不到”错误。forfiles/p“C:\Users\hi\Desktop\test”/m*.jpg/d-1/C“cmd/C del@path”