Results 1 to 6 of 6

Thread: Creating automatic log file folder

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    29

    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

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    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...
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485

    Re: Creating automatic log file folder

    vb Code:
    1. Dim szTmpPath As String = System.IO.Path.Combine(Application.StartupPath, "Log")
    2.  
    3. Dim dirInfo As New System.IO.DirectoryInfo(szTmpPath)
    4.  
    5. '   if folder not exist, create
    6. If Not dirInfo.Exists Then dirInfo.Create()

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    29

    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..

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Creating automatic log file folder

    Then it's time to enhance it further.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width