2

i have a question
I get this script

for /f "tokens=* " %%d in ('tracert -4 -d 8.8.8.8') do (
echo %%d
) >>test.txt

but I would like condition as below 1. save new file when i do run this script anytime example

run 1 > create new file1
run 2 > create new file2
run 3 > create new file3

ever
  1. the script continues run 1 minute

  2. if i need to file name is date time is there anyways

thank for answer

assb
  • 21
  • 3
  • 1
    does [this](https://stackoverflow.com/a/18024049/2152082) answer your question? – Stephan May 01 '20 at 07:55
  • Add to your question: What version of Windows. – somebadhat May 01 '20 at 12:20
  • 1
    why don't just use `tracert -4 -d 8.8.8.8>FILE`? – ScriptKidd May 02 '20 at 00:28
  • Does this answer your question? [How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?](https://stackoverflow.com/questions/203090/how-do-i-get-current-date-time-on-the-windows-command-line-in-a-suitable-format) – somebadhat May 04 '20 at 14:49

1 Answers1

0

Based on the comment posted above by Stephan you can do something like that :

(independent of locale settings)

@echo off
Call :GetFileNameWithDateTime
echo %filename%.txt
( @for /f "tokens=* " %%d in ('tracert -4 -d 8.8.8.8') do echo %%d )>%filename%.txt
If Exist %filename%.txt Start "" %filename%.txt
pause
Exit
::-----------------------------------------------------------------------------------
:GetFileNameWithDateTime
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set "MyDate=%%x"
set "filename=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%-%MyDate:~8,2%-%MyDate:~10,2%"
exit /b
::------------------------------------------------------------------------------------

Hackoo
  • 18,337
  • 3
  • 40
  • 70