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!

Creating a log file

Status
Not open for further replies.

Jesse222

IS-IT--Management
Aug 6, 2004
7
0
0
CA
Hello,

I want to add some logging into an existing script. The code here works but I was wondering if there is a way to have it create the *.log file on a subdir from where the script is getting run from. then I do not have to code the full path to the log file.

Right now when I run this code it will create a log foleder and file under my user profile name.

Any hints on where to look would be appreciated. Or any suggestion in the existing code as well.

Const ForAppending = 8
Dim strLogFile, strDate

strDate = Date
strLogFile = "Logs\Find_Primary_" & Year(strDate) & Month(strDate) & Day(strDate) & ".log"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("testingthis.log", ForAppending, True)


objLogFile.WriteBlankLines(2)
objLogfile.WriteLine "Testing my new log file"
objLogFile.Close
 
Opps sorry, I left in some of my testing. Here is the code once more.



Const ForAppending = 8
Dim strLogFile, strDate

strDate = Date
strLogFile = "Logs\Find_Primary_" & Year(strDate) & Month(strDate) & Day(strDate) & ".log"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)


objLogfile.WriteLine "Testing my new log file"
objLogFile.Close
 
If you do not put a path in with the file name, it will be created where the script is executed from.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
can this work for an Access 2003 run-time app?
 
Sure, why not? If you can execute from a command line you can script it.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top