batch file to create text file HELP

March 18, 2009 at 06:02:28
Specs: Windows XP
:Create the report for this device scan
set file_name=%computername%_%date:~-10,2%-%date:~-7,2%-%date:~-4,4%_%time:~-11,2%-%time:~-8,2%-%time:~-5,2%.txt
copy nul %file_name%

above is my code. When I get this working, I will replace the copy line with:

copy nul Data\%computername%\%file_name%

both code versions above gives error for the copy line: "the syntax of the command is incorrerct"

Anyone know what I'm doing wrong?

See More: batch file to create text file HELP

Report •

March 18, 2009 at 07:29:56
Its a problem with the formating of the date/time. There are a number of methods out there to do what I was trying to do, this is the only one that worked for me (SEE NOTE BELOW!!!):

NOTE: I found that it only works when you add a space after the ':' as the link had done for the date '/'. Here is my code:

@for /f "tokens=1-5 delims=/ " %%d in ("%date%") do @set fdate=%%e-%%f-%%g
@for /f "tokens=1-5 delims=: " %%d in ("%time%") do @set ftime=%%d-%%e
@echo Date-Time reformat as: %fdate%_%ftime%

Note that, for the purposes of testing, you need to test for inconsistencies in formating (i.e. 9am and 12am have differing digits; would have made things easier if MS made the format 09am, but we can't expect MS to use common sense, lol).

Report •
Related Solutions

Ask Question