Computing.Net > Forums > Programming > batch file to create text file HELP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file to create text file HELP

Reply to Message Icon

Name: gunslingor
Date: March 18, 2009 at 06:02:28 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

: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?



Sponsored Link
Ads by Google

Response Number 1
Name: gunslingor
Date: March 18, 2009 at 07:29:56 Pacific
Reply:

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!!!):
http://www.computerhope.com/issues/...

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).


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file to create text file HELP

help with Batch file to change .txt www.computing.net/answers/programming/help-with-batch-file-to-change-txt/14693.html

Batch file help www.computing.net/answers/programming/batch-file-help/11754.html

batch script to parse text file www.computing.net/answers/programming/batch-script-to-parse-text-file/16793.html