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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to timestamp file name

Status
Not open for further replies.

Mjamm

IS-IT--Management
Dec 24, 2001
88
US
Hi, I am in need of help to name a file using a timestamp naming convention. I have two examples listed. Example #2 names the file like I want, however Example #1 is the script I need to use.

Can some explain how to modify Example #1 to include the TIME onto the name of the capture file???

Thanks in advance for any assistance!

*********************************************************
EXAMPLE #1
string szRepDate, szTodaysDate, szTimeString, szThisYear, szThisMonth
string szThisDay, szDestPrimary, szDestBackup
string szTempFile = szTempCapDir

strcat szTempFile "temp.txt"

ltimestrs $ltime szTodaysDate szTimeString ;Convert date to xx/xx/xx
strextract szThisMonth szTodaysDate "/" 0 ;Extract the month for the name.
strextract szThisDay szTodaysDate "/" 1 ;Extract the day for the name.
strextract szThisYear szTodaysDate "/" 2 ;Extract the year for the name.

strfmt szThisMonth "%02.2s" szThisMonth ;Format the Month part of name.
strfmt szThisDay "%02.2s" szThisDay ;Format the Day part of name.

strfmt szRepDate "%s%s%s.txt" szThisMonth szThisDay szThisYear

;Set the capture file name
;Using MMDDYY.txt format

strfmt szDestPrimary "%s%s" szPrimaryDirectory szRepDate
strfmt szDestBackup "%s%s" szBackupDirectory szRepDate

if copyfile szTempFile szDestPrimary ;Copy the report to primary location.
else
copyfile szTempFile szDestBackup ;Copy the file to backup location if.
;the primary is not available.
endif
**********************************************************
EXAMPLE #2

string sCapPath, sCapFile, sCapFile2, sNewFile
integer iDay, iMonth
integer iYear, iHour
integer iMin, iSec

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt sNewFile "%s%d%02d%02d%s%02d%02d%02d" "ACD_" iYear iMonth iDay "_" iHour iMin iSec
strcat sNewfile ".TXT"
strfmt sCapFile "%s\temp.txt" sCapPath
strfmt sCapFile2 "%s\%s" sCapPath sNewFile
shortpath sCapFile sCapFile
rename sCapFile sCapFile2
;usermsg sNewfile
 
I think this should do the trick:

proc main
string szRepDate, szTodaysDate, szTimeString, szThisYear, szThisMonth
string szThisDay, szDestPrimary, szDestBackup, szTempCapDir
string szBackupDirectory, szPrimaryDirectory
string szTempFile = szTempCapDir
integer iDay, iMonth
integer iYear, iHour
integer iMin, iSec

strcat szTempFile "temp.txt"

ltimestrs $ltime szTodaysDate szTimeString ;Convert date to xx/xx/xx
strextract szThisMonth szTodaysDate "/" 0 ;Extract the month for the name.
strextract szThisDay szTodaysDate "/" 1 ;Extract the day for the name.
strextract szThisYear szTodaysDate "/" 2 ;Extract the year for the name.

strfmt szThisMonth "%02.2s" szThisMonth ;Format the Month part of name.
strfmt szThisDay "%02.2s" szThisDay ;Format the Day part of name.
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt szRepDate "%s%s%s%s%02d%02d%02d.txt" szThisMonth szThisDay szThisYear "_" iHour iMin iSec

;Set the capture file name
;Using MMDDYY.txt format

strfmt szDestPrimary "%s%s" szPrimaryDirectory szRepDate
strfmt szDestBackup "%s%s" szBackupDirectory szRepDate

if copyfile szTempFile szDestPrimary ;Copy the report to primary location.
else
copyfile szTempFile szDestBackup ;Copy the file to backup location if.
;the primary is not available.
endif
endproc


aspect@aspectscripting.com
 
Knob,
My example was just a section of my script, so I pasted your modification into my script from the Samples on the Procomm CD.

Now I am getting the following error while compiling.

ACD_COLLECTION2.WAS:
Error C027 Line 83: Invalid identifier or name: "c:\temp\"
Error C027 Line 85: Invalid identifier or name: "c:\ACDReports\"
Error C027 Line 85: Invalid identifier or name: "t:\ACDReports\"

My entire script is below!!!




;****************************************************************************
;* Define Statements *
;****************************************************************************
#Define szPrimaryDirectory "t:\ACDReports\" ;Set the Primary directory.
#Define szBackupDirectory "c:\ACDReports\" ;Set the Backup directory.
#define szTempCapDir "c:\temp\" ;Set the Temp directory.
#define szTempCapName "temp.txt" ;Set name for temporary CAP file
#Define szStartTime "07:00:00" ;24hr format.
#Define szEndTime "07:45:30"


;****************************************************************************
;* Main Procedure *
;****************************************************************************
proc main

while 1 ;Loop forever.
yield ;Yield processing time back to CPU.
if stricmp $time24 szStartTime ;Wait for time to start capture.
CaptureData() ;Go to capture subroutine.
yield ;Yield processing time back to CPU.
pause 1
MoveData() ;Go to the Move file routine.
endif
endwhile
endproc


;****************************************************************************
;* CaptureData *
;* This procedure captures the data from the current connection *
;****************************************************************************
proc CaptureData

set capture path szTempCapDir ;Set the capture path.
set capture file szTempCapName ;Set the capture file name.

set capture overwrite on ;This can be set to append as well.
;Simply set this to OFF

capture on ;Begin the capture.

while 1 ;Loop while capturing data.
if stricmp $time24 szEndTime ;Wait for time to end capture.
capture off ;Turn off the capture.
exitwhile ;Return to main procedure.
endif
endwhile
endproc


;****************************************************************************
;* MoveData *
;* This procedure copies the captured data to the specified directory. *
;****************************************************************************
proc MoveData

string szRepDate, szTodaysDate, szTimeString, szThisYear, szThisMonth
string szThisDay, szTempCapDir
string szDestPrimary, szDestBackup
string szBackupDirectory, szPrimaryDirectory
string szTempFile = szTempCapDir
integer iDay, iMonth
integer iYear, iHour
integer iMin, iSec

strcat szTempFile "temp.txt"

ltimestrs $ltime szTodaysDate szTimeString ;Convert date to xx/xx/xx
strextract szThisMonth szTodaysDate "/" 0 ;Extract the month for the name.
strextract szThisDay szTodaysDate "/" 1 ;Extract the day for the name.
strextract szThisYear szTodaysDate "/" 2 ;Extract the year for the name.

strfmt szThisMonth "%02.2s" szThisMonth ;Format the Month part of name.
strfmt szThisDay "%02.2s" szThisDay ;Format the Day part of name.
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt szRepDate "%s%s%s%s%02d%02d%02d.txt" szThisMonth szThisDay szThisYear "_" iHour iMin iSec

;Set the capture file name
;Using MMDDYY.txt format

strfmt szDestPrimary "%s%s" szPrimaryDirectory szRepDate
strfmt szDestBackup "%s%s" szBackupDirectory szRepDate

if copyfile szTempFile szDestPrimary ;Copy the report to primary location.
else
copyfile szTempFile szDestBackup ;Copy the file to backup location if.
;the primary is not available.
endif

endproc
 
In the MoveData proc, get rid of the line:

string szBackupDirectory, szPrimaryDirectory

and change string szThisDay, szTempCapDir to read just string szThisDay. I added these variables since they were not listed in the original (to make the compile work on my machine), but since you already have them defined you do not need these two lines as I had modified them.


aspect@aspectscripting.com
 
Knob,
I tried that already and got the following errors during compiling - Listed below....

What am I doing wrong.... Ugggg!


ACD_COLLECTION2.WAS:
Error C027 Line 86: Invalid identifier or name: "c:\ACDReports\"
Error C027 Line 86: Invalid identifier or name: "t:\ACDReports\"
Error C023 Line 107: Invalid expression token: SZDESTPRIMARY
Error C163 Line 107: Invalid string variable
Error C023 Line 108: Invalid expression token: SZDESTBACKUP
Error C163 Line 108: Invalid string variable
Error C023 Line 110: Invalid expression token: SZDESTPRIMARY
Error C022 Line 110: Missing token
Error C023 Line 112: Invalid expression token: SZDESTBACKUP
Error C022 Line 112: Missing token
 
Modifying those two lines worked for me. Here is what the script looks like when I do so:

;****************************************************************************
;* Define Statements *
;****************************************************************************
#Define szPrimaryDirectory "t:\ACDReports\" ;Set the Primary directory.
#Define szBackupDirectory "c:\ACDReports\" ;Set the Backup directory.
#define szTempCapDir "c:\temp\" ;Set the Temp directory.
#define szTempCapName "temp.txt" ;Set name for temporary CAP file
#Define szStartTime "07:00:00" ;24hr format.
#Define szEndTime "07:45:30"


;****************************************************************************
;* Main Procedure *
;****************************************************************************
proc main

while 1 ;Loop forever.
yield ;Yield processing time back to CPU.
if stricmp $time24 szStartTime ;Wait for time to start capture.
CaptureData() ;Go to capture subroutine.
yield ;Yield processing time back to CPU.
pause 1
MoveData() ;Go to the Move file routine.
endif
endwhile
endproc


;****************************************************************************
;* CaptureData *
;* This procedure captures the data from the current connection *
;****************************************************************************
proc CaptureData

set capture path szTempCapDir ;Set the capture path.
set capture file szTempCapName ;Set the capture file name.

set capture overwrite on ;This can be set to append as well.
;Simply set this to OFF

capture on ;Begin the capture.

while 1 ;Loop while capturing data.
if stricmp $time24 szEndTime ;Wait for time to end capture.
capture off ;Turn off the capture.
exitwhile ;Return to main procedure.
endif
endwhile
endproc


;****************************************************************************
;* MoveData *
;* This procedure copies the captured data to the specified directory. *
;****************************************************************************
proc MoveData

string szRepDate, szTodaysDate, szTimeString, szThisYear, szThisMonth
string szThisDay
string szDestPrimary, szDestBackup
string szTempFile = szTempCapDir
integer iDay, iMonth
integer iYear, iHour
integer iMin, iSec

strcat szTempFile "temp.txt"

ltimestrs $ltime szTodaysDate szTimeString ;Convert date to xx/xx/xx
strextract szThisMonth szTodaysDate "/" 0 ;Extract the month for the name.
strextract szThisDay szTodaysDate "/" 1 ;Extract the day for the name.
strextract szThisYear szTodaysDate "/" 2 ;Extract the year for the name.

strfmt szThisMonth "%02.2s" szThisMonth ;Format the Month part of name.
strfmt szThisDay "%02.2s" szThisDay ;Format the Day part of name.
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt szRepDate "%s%s%s%s%02d%02d%02d.txt" szThisMonth szThisDay szThisYear "_" iHour iMin iSec

;Set the capture file name
;Using MMDDYY.txt format

strfmt szDestPrimary "%s%s" szPrimaryDirectory szRepDate
strfmt szDestBackup "%s%s" szBackupDirectory szRepDate

if copyfile szTempFile szDestPrimary ;Copy the report to primary location.
else
copyfile szTempFile szDestBackup ;Copy the file to backup location if.
;the primary is not available.
endif

endproc




aspect@aspectscripting.com
 
Thanks Knob!!!! You are a life saver. It worked like a charm. I just pasted your posting over my script and it executed correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top