0

@ftime我想忽略输出的秒数forfiles

forfiles /P "%userprofile%\Desktop\folder" /M "test.rar" /C "cmd /c echo sucessufull at %@ftime:~0,2%:%@ftime:~3,2%h"

尝试使用这种方式,但我认为forfiles不允许使用%.

4

2 回答 2

3
这是直接使用命令的基本示例,以保持主题:
@ForFiles /P "%UserProfile%\Desktop\folder" /M "test.rar" /C "Cmd /V /C Set _=@FTime&Echo successful at !_:~,5!"

还有一个更完整/更强大的例子:

@"%__AppDir__%forfiles.exe" /P "%UserProfile%\Desktop\folder" /M "test.rar" /C "0x22%__AppDir__%cmd.exe0x22 /V /C If @IsDir==FALSE (Set 0x22_=@FTime0x22 & Echo successful at !_:~,5!)"
于 2020-06-23T20:26:32.517 回答
2

的特殊@- 变量forfiles,如@ftime,与普通环境变量无关, -%符号用于扩展它们。

有两种选择:

  1. 捕获forfileswith的输出for /F

     for /F "tokens=1-2 delims=:" %%I in ('
         forfiles /P "%UserProfile%\Desktop\Folder" /M "test.rar" /C "cmd /C if @isdir==FALSE echo @ftime"
     ') do (
         echo successful at %%I:%%Jh
     )
    
  2. 嵌套for /F循环内部forfiles

     forfiles /P "%UserProfile%\Desktop\Folder" /M "test.rar" /C "cmd /C if @isdir==FALSE for /F 0x22tokens=1-2 delims=:0x22 %%I in (0x22@ftime0x22) do echo successful at %%I:%%Jh"
    

    十六进制代码0x22代表引号",只有forfiles.

于 2020-06-23T20:04:36.083 回答