Results 1 to 11 of 11

Thread: Check if Folder Exists

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381

    Check if Folder Exists

    On a recent project I thought I had completed it worked fine on my developement machine but went belly-up when moved to my office pc at the church. It didn't take too long to figure out what was causing the problem.

    The program would keep a record of the date and time the user logged on and off and automatically backup my database when the program was exited. Both the logfile and the database bakup are stored in subdirectories of the application directory. On my development system I had manually created the sub-directories way back when and had forgotten about them.

    How can I have my program check if the directories exist when the application loads and if not, creat them?

    On a somewhat related question, the log file is a text file where each entry is a seperate line preceeded by the date such as:

    10/24/2001 - Billy Jones logged on succesfully at 10:28.
    10/24/2001 - Billy Jones logged offsuccesfully at 12:13
    10/24/2001 - Database was automatically backed up at 12:13.

    Over time this file could grow way too large, especially when the program could be logged into and out of numerous times a day.

    Is there a way to have my program automaticcally check this file before it writes to it and delete all lines that are more than 30 days old?

    Thanks,
    Rev. Michael L. Burns

  2. #2
    Matthew Gates
    Guest
    To check if a folder exists:


    VB Code:
    1. If Len(Dir$("C:\MyDir", vbDirectory)) <= 0 Then MkDir "C:\MyDir"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Probably the easiest way would be to programmatically change to the directory/directories in question. If it does not exist, you will get an error. Trap that error in an On Error Goto statement, and then programmatically create the directory/directories.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Matthew beat me to it, so all I have to say is "but then why go though all that error trapping when you can do what you want with one line of code."

    Signed,

    Egg On Face Hack Programmer

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Matthew and Hack,

    Thank you both for your quick replies. I will check this out when I get home this evening.

    Any ideas concerning the second part of my post.

    Pastor Mike

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Orginally posted by Rev. Michael L. Burns
    Is there a way to have my program automaticcally check this file before it writes to it and delete all lines that are more than 30 days old?
    It depends on what you mean by automatically. You could write a routine the executes each time your program does, and have it do the check and delete stuff. Calculating 30 days from the current date is childs play, so I won't bother with that. Is this the kind of "automatic" that you mean, or do you want your "check it/delete it" sub routine to only run once every 30 days?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Hack,

    I want it to check everytime my program loads and delete any entries older than 30 days.

    Pastor Mike

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Ok. Piece of cake. Write a sub routine that does that, and call it from your Form_Load event. Since the date is the first ten bytes of each line, your task is even easier. Are you stuck on how to write this routine? If so, I'm sure I could whip something up right quick, but at the moment, I have to go to a meeting.

  9. #9
    Addicted Member tcurrier's Avatar
    Join Date
    May 1999
    Location
    Northeastern Pa./USA
    Posts
    255
    By the way, I found this out the hard way :

    For us 'Network' people,

    If you specify a UNC path name, you must include a TRAILING back slash : ( \ )

    Code:
    
                                                                          
    If Len(Dir$("\\AS_SISCFSVR01\MYDIRECTORY\)) <= 0 
    
    Not sure why, but it won't work without it. (I'm on NT 4.0)
    VB6 Enterprise SP4

  10. #10
    Addicted Member cbond's Avatar
    Join Date
    Apr 2001
    Location
    AZ - USA
    Posts
    148

    VB World Tip

    Regarding if a directory exists there is an article on just that on VB World at

    http://www.vb-world.net/files/tip528.html

    I have used the method mentioned there serveral times.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Thanks everyone. Got the directory stuff working thanks to your help. However I still need help with the second part of the question.

    Hack, I'd like to take you up on your offer to give some example code. It would be most appreciated.

    Pastor Mike

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