|
-
Oct 24th, 2001, 07:37 AM
#1
Thread Starter
Hyperactive Member
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
-
Oct 24th, 2001, 07:40 AM
#2
To check if a folder exists:
VB Code:
If Len(Dir$("C:\MyDir", vbDirectory)) <= 0 Then MkDir "C:\MyDir"
-
Oct 24th, 2001, 07:41 AM
#3
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.
-
Oct 24th, 2001, 07:43 AM
#4
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
-
Oct 24th, 2001, 11:57 AM
#5
Thread Starter
Hyperactive Member
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
-
Oct 24th, 2001, 12:19 PM
#6
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?
-
Oct 24th, 2001, 12:34 PM
#7
Thread Starter
Hyperactive Member
Hack,
I want it to check everytime my program loads and delete any entries older than 30 days.
Pastor Mike
-
Oct 24th, 2001, 12:38 PM
#8
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.
-
Oct 24th, 2001, 01:48 PM
#9
Addicted Member
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)
-
Oct 24th, 2001, 02:19 PM
#10
Addicted Member
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.
-
Oct 24th, 2001, 02:30 PM
#11
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|