Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a new .txt file with timestamp 1

Status
Not open for further replies.

olderwhite

Programmer
Dec 12, 2010
4
0
0
US
Hi all,

I have a script that I need to create a new .txt file in Drive C:\ with a time stamp in the filename. I can create the file by naming it, but cannot call a previously created string for the new file name. Also, I cannot rename the file by calling a previously created sring. ( i.e. s1)

Thanks...

Olderwhite
 
I have several samples scripts on my site (link below) that show how to create filenames based on the date and time. You can then use those filenames in fopen/fread/etc. commands or in a set command if that is how you are accessing the file.

 
Thanks for the reply,

I can create the filename but i cannot use it to create the file. Then I tried to re-name the file, Still will not call the s1 string for the filename. Here is ithe script:
Thanks for your help,
Olderwehite

proc QSTFILE_GEN

string Fname = "C:\QST\Fwrite.txt" ; Name of file to be created.

if fopen 0 Fname CREATE ; Create and open file.
fputs 0 s7 ; Write QST File.
fclose 0 ; Close the file.

if SUCCESS ; If the sendfile is successful, say so

call RENAME_FILE

endif

endif

endproc

proc RENAME_FILE

string Fname = "C:\QST\Fwrite.txt" ; Name of file to rename.
string NewFName = s1 ; New name for the file.

if not rename Fname NewFName ; Rename the file.
errormsg "Couldn't rename `"%s`" to `"%s`"." Fname NewFName

endif

endproc
 
proc PASSQST_GEN

;s0 is for the cycle number
;s7 is for the QST file update
;s4 is for the serial number
;s3 is for part number and revision
;s6 is for Plexus ID
;s1 for QST fileName

string OutPutString
string TimeStampingQST = " "
integer iDay, iMonth, iYear, iHour, iMinute, iSecond
string FailID = " "

strset OutPutString 0 0 255

s1 = " "

ltimeints $LTIME iYear iMonth iDay iHour iMinute iSecond

strfmt TimeStampingQST "%d%02d%02d%02d%02d%02d" iYear iMonth iDay iHour iMinute iSecond

strfmt FailID "%02d" i2

strcat s1 "C:\QST\"
strcat s1 "FT00001_"
strcat s1 TimeStampingQST
strcat s1 ".qst"


;usermsg TimeStampingQST ; message.
;usermsg s1 ; message.

switch i7
case 0 ;Pass Case
strcat OutPutString "EV|"
strcat OutPutString "|"
strcat OutPutString s4
strcat OutPutString "|"
strcat OutPutString TimeStampingQST
strcat OutPutString "|||"
strcat OutPutString s0
strcat OutPutString "|TEST|FT00001|"
strcat OutPutString s6
strcat OutPutString "|||F1|N|PASS|NA|"
strcat OutPutString s3
strcat OutPutString "|ProCommTestScript|Prelim 1.0|FT00001|||||277|"
strcat OutPutString "|||00000|680|1||BOI_6802||"

s7 = OutPutString
call QSTFILE_GEN
endcase

endswitch
endproc

proc FAILQST_GEN

;s7 is for the QST file update
;s4 is for the serial number
;s3 is for part number and revision
;s6 is for Plexus ID
;s1 for QST fileName

string OutPutString
string TimeStampingQST = " "
integer iDay, iMonth, iYear, iHour, iMinute, iSecond
string FailID = " "

strset OutPutString 0 0 255

s1 = " "

ltimeints $LTIME iYear iMonth iDay iHour iMinute iSecond

strfmt TimeStampingQST "%d%02d%02d%02d%02d%02d" iYear iMonth iDay iHour iMinute iSecond

strfmt FailID "%02d" i2

strcat s1 "C:\QST\"
strcat s1 "FT00001_"
strcat s1 TimeStampingQST
strcat s1 ".qst"


usermsg TimeStampingQST ; message.
usermsg s1 ; message.



;case 1 ;Fail Case
strcat OutPutString "EV|"
strcat OutPutString s3
strcat OutPutString "|"
strcat OutPutString s4
strcat OutPutString "|"
strcat OutPutString TimeStampingQST
strcat OutPutString "|||"
strcat OutPutString "|"
strcat OutPutString "TEST|FT00001|"
strcat OutPutString s6
strcat OutPutString "|||F1|N|FAIL|"
strcat OutPutString "FAILED"
strcat OutPutString "|"
strcat OutPutString "F1"
strcat OutPutString "|ProCommTestScript|1.0|FBT|||||277|"
strcat OutPutString S5
strcat OutPutString "|||00000|680|1||BOI_6802||"
s7 = OutPutString
usermsg s7 ; message.

call QSTFILE_GEN



endproc

proc QSTFILE_GEN

string Fname = "C:\QST\Fwrite.txt" ; Name of file to be created.

if fopen 0 Fname CREATE ; Create and open file.
fputs 0 s7 ; Write QST File.
fclose 0 ; Close the file.

if SUCCESS ; If the sendfile is successful, say so

call RENAME_FILE

endif

endif

endproc

proc RENAME_FILE

string Fname = "C:\QST\Fwrite.txt" ; Name of file to rename.
string NewFName = s1 ; New name for the file.

if not rename Fname NewFName ; Rename the file.
errormsg "Couldn't rename `"%s`" to `"%s`"." Fname NewFName

endif

endproc
 
Yes,
I am getting all of the correct output. I put the user messages in to varify. For some reason I cannot use the string data to name the file. I am able to put the s7 data into the file. All I need to do is somehow name or re-name the file with the timestamp.

Thanks,

olderwhite
 
I see a couple places in the script where you have this line:

s1 = " "

then later use strcat to add to the string. However, that leading space will still be present (you want to use s1 = "" instead) and likely cause problems for file operations.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top