我有一个问题我得到这个脚本
for /f "tokens=* " %%d in ('tracert -4 -d 8.8.8.8') do (
echo %%d
) >>test.txt
但是我想要以下条件1.当我随时运行此脚本时,请保存新文件例子
run 1 > create new file1
run 2 > create new file2
run 3 > create new file3
ever
脚本继续运行1分钟
如果我需要文件名是日期时间,反正还有
感谢回答
Windows 10 64位。
如何在Windows 10 CMD和%time%中使用秒。毫秒为文件名加上时间戳。 %time%的早期版本(XP 32位?)必须以不同的方式使用。参见echo %time%
CMD:
@rem Traceroute output to text file. Timestamp filename. Windows 10 64-bit. Does not require admin privileges.
cmd /q /e /v:off
for /f "tokens=* " %g in ('tracert -4 -d 8.8.8.8') do echo %g>>test%TIME:~10,5%.txt
脚本:
@rem Traceroute output to text file. Timestamp filename. Windows 10 64-bit. Does not require admin privileges.
@echo off
setlocal enableextensions disabledelayedexpansion
for /f "tokens=* " %%g in ('tracert -4 -d 8.8.8.8') do echo %%g>>test%TIME:~10,5%.txt
exit /b
结果:
环境变量编辑:
https://ss64.com/nt/syntax-substring.htmlhttps://ss64.com/nt/syntax-replace.htmlhttps://ss64.com/nt/syntax-args.html
%name:~n% Skips the first n letters and returns the rest
%name:~n,m% Skips n letters and returns the next m
%name:~,m% First (leftmost) m letters
%name:~,-m% Last (rightmost) m letters
Using the environment variable var=ABCDEFG, here are some examples:
Command Prints
ECHO %var% ABCDEFG
ECHO %var:~2% CDEFG
ECHO %var:~2,3% CDE
ECHO %var:~,3% ABC
ECHO %var:~,-3% ABCD