Creating automatic log file folder
Hi all,
Currently i developing a system which require me to create a log file.
My code is working but I need to enhance it make the log file folder create automatically bcoz right now i have to create the folder manually in the debug folder.
Here is my code:
FileOpen(1, (Application.StartupPath & "\Log\" & lotno & ".txt"), OpenMode.Append)
PrintLine(1, "Start Time : ", Now())
PrintLine(1, "Lot Number : ", lotno)
PrintLine(1, "Test Software : ", title)
PrintLine(1, "Staff ID : ", operID)
PrintLine(1,
PrintLine(1, "")
FileClose(1)
Hope someone can help me :D
Re: Creating automatic log file folder
Is this vb.net? I've never heard of FileOpen and PrintLine commands. Also what do you mean by developing a system?
Either way I'm sure google would give you the answer in seconds if you would just ask it a question...
Re: Creating automatic log file folder
Get rid of that VB6-style I/O altogether. In VB.NET you use the members of the System.IO namespace or the My.Computer.FileSystem object to read and write files. For instance, to write multiple lines to a text file you should either open a StreamWriter and call WriteLine on it multiple times or, more simply call File.WriteAllLines or .AppendAllLines. Those last two options will also create the folder if required, while I'm not sure about the StreamWriter. Probably not but you can test that. If not the Directory.CreateDirectory will do it.
Re: Creating automatic log file folder
vb Code:
Dim szTmpPath As String = System.IO.Path.Combine(Application.StartupPath, "Log")
Dim dirInfo As New System.IO.DirectoryInfo(szTmpPath)
' if folder not exist, create
If Not dirInfo.Exists Then dirInfo.Create()
Re: Creating automatic log file folder
Hi guys,
Thanks for ur help..
Actually this system is migration from vb6 to vb.net..
I just enhanced it from the previous source cord..
Re: Creating automatic log file folder
Then it's time to enhance it further. ;)