@ftime
我想忽略输出的秒数forfiles
:
forfiles /P "%userprofile%\Desktop\folder" /M "test.rar" /C "cmd /c echo sucessufull at %@ftime:~0,2%:%@ftime:~3,2%h"
尝试使用这种方式,但我认为forfiles
不允许使用%
.
@ftime
我想忽略输出的秒数forfiles
:
forfiles /P "%userprofile%\Desktop\folder" /M "test.rar" /C "cmd /c echo sucessufull at %@ftime:~0,2%:%@ftime:~3,2%h"
尝试使用这种方式,但我认为forfiles
不允许使用%
.
@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!)"
的特殊@
- 变量forfiles
,如@ftime
,与普通环境变量无关, -%
符号用于扩展它们。
有两种选择:
捕获forfiles
with的输出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
)
嵌套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
.