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!

Append log file when exists otherwise create one

Status
Not open for further replies.

BigC72

MIS
Oct 15, 2004
69
0
0
US
I have a script that performs a number of different functions for me including creating a simple log file that indicates what has been done...I would like to adapt this script so that rather than running a slightly modified version that creates a different log file the original will identify that either the log file does not yet exist and it must create one (which it does just fine now) OR the log file is already there so I just need to add my new entries to it. I'll copy in the code for review. I'm sure I'm just overthinking it (or underthinking for that matter) but will appreciate any help you folks can offer...

Code:
Option Explicit
'This is the location of the raw 835 files to be processed
CONST PATH = "\\anh-ssisql\ssiapp\renws\billing\uploadh\"
CONST ForWriting = 2
 
' declare the various variables
Dim strDate_2_Copy, strShare, strShareB, objLogFile
Dim fso, objFolder, colFiles, objFile, strFile, remitFile, fileDate

Set fso = CreateObject("Scripting.FileSystemObject")

strDate_2_Copy = Now()
'This is the default location the 835 files must be placed in order for the EDI agent to process them   
strShare = "E:\inserver6\EDI\edi_start\"
'This is the location the EDI process places the 835 files once they have been processed by the system
strShareB = "E:\inserver6\EDI\edi_backup" 

fileDate = Replace(Date(), "/", "")   'used to establish a date variable to be used later in naming the edicopy log file 

If fso.FolderExists(PATH) Then			'makes certain that the path defined above exists and then establishes all files in that directory
    Set objFolder = fso.GetFolder(PATH)
    Set colFiles = objFolder.Files
Else
    Wscript.Echo "Can't find the " & PATH & " folder"
    Wscript.Quit
End if

set objLogFile = fso.CreateTextFile("E:\inserver6\log\edicopy" & fileDate & ".txt", ForWriting, True) 

For Each strFile in colFiles
    Set objFile = fso.GetFile(strFile)	'assigns the files to the strFile variable
	If fso.GetExtensionName(strFile) = "835" Then 'it will only pull across 835 files from the directory and nothing else
	remitFile = objFile.Name  'gets the file name of each file to be used in a later step
	If DateDiff("d", objFile.DateLastModified, strDate_2_Copy) < 4 Then	'it will only copy files that have been created in the last 2 days
	If Not fso.FileExists(strShareB & "\" & remitFile) Then 'see if file has already been copied and processed if so loop and check the next file
	fso.CopyFile strFile, strShare, True   'any files found to meet the above criteria is copied to the edi_start directory
	objLogFile.Write "File " & remitFile & " has been copied to the edi_start directory for processing."
	objLogFile.WriteLine
	Else
	objLogFile.Write "File " & remitFile & " has already been processed and will not be copied."
    objLogFile.WriteLine
	End If
	End If
	End If
	
	Set objFile = Nothing
	
	
Next

Wscript.Quit

 
Replace this:
set objLogFile = fso.CreateTextFile("E:\inserver6\log\edicopy" & fileDate & ".txt", ForWriting, True)
With this:
Set objLogFile = fso_OpenTextFile("E:\inserver6\log\edicopy" & fileDate & ".txt", 8, True, True)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My only question PHV is will this method still create the text file if it doesn't already exist?

What is occurring is this script is being run twice per day...Ideally the first run of the day would create the file for that day as it won't exist and the second run would identify that the file exists and simply append any "loggable" information to that file...
 
Thank you for your help/guidance...I think I have it performing in line with my needs now...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top