-
Dec 3rd, 2003, 11:22 AM
#1
Thread Starter
Supreme User
Check if file exists
VB Code:
Private Function CheckForFile(FileName) As Boolean
'Check if file exists
CheckForFile = (Dir(FileName) <> "")
End Function
Private Sub Form_Load()
If CheckForFile(App.Path & "\Yourfile") Then
'Do the correct thing
Else
'Do the incorrect thing
End If
End Sub
Thanks Si_The_Geek for updating my previous code
Last edited by Madboy; Dec 3rd, 2003 at 12:02 PM.
-
Dec 3rd, 2003, 05:42 PM
#2
-
Dec 4th, 2003, 08:53 AM
#3
Thread Starter
Supreme User
Just keeping everyone up to date,
Not everybody backtrack threads you know
-
Dec 5th, 2003, 11:13 AM
#4
Hyperactive Member
This should be faster
Code:
Private Function CheckForFile(byval FileName as string) As Boolean
'Check if file exists
CheckForFile = Lenb(Dir(FileName))
End Function
-
Dec 5th, 2003, 01:53 PM
#5
Thread Starter
Supreme User
Ok, i might try that later
-
Dec 7th, 2003, 03:38 PM
#6
-
Dec 7th, 2003, 03:44 PM
#7
Thread Starter
Supreme User
Some n00bs dont know how to search, and even if you do search, you have to backtrack through the list
-
Dec 7th, 2003, 04:02 PM
#8
-
Dec 15th, 2003, 05:41 PM
#9
PowerPoster
I'm used to this one:
VB Code:
Public Function Exists(iFileName As String) As Boolean
'Check filename
Exists = (Len(Dir(iFileName, vbArchive Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem)) > 0)
End Function
-
Dec 15th, 2003, 05:43 PM
#10
Thread Starter
Supreme User
In a sense that is better, it searches for all atributes of the file
-
Dec 25th, 2003, 05:04 PM
#11
Hyperactive Member
But doesn't the Dir command automatically searches all different types of file attributes by default? So what's the sense specifiying the type?
And secondly...how in anyway is Lenb(Dir....etc) faster that just plain Dir(...)?
For me the shortest way proves to be the fastest and most easily understood...
VB Code:
If Dir(FilePath)<>"" Then
DoThis
Else
DoThisInstead
End If
Just my suggestion....
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Dec 25th, 2003, 07:22 PM
#12
Originally posted by Protocol
And secondly...how in anyway is Lenb(Dir....etc) faster that just plain Dir(...)?
For me the shortest way proves to be the fastest and most easily understood...
VB Code:
If Dir(FilePath)<>"" Then
DoThis
Else
DoThisInstead
End If
Just my suggestion....
In general, numeric comparisons are much faster than string comparisons. Shortest code does not always equal fastest code.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Dec 26th, 2003, 12:07 AM
#13
Hyperactive Member
@ crptcblade....
I read yah and I understand what your saying...
Guess I misphrased when I said "fastest"....
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Dec 26th, 2003, 02:38 PM
#14
Thread Starter
Supreme User
....as long as it works thats the main thing for me.
-
Jan 2nd, 2004, 05:12 AM
#15
Addicted Member
Ok guys & Gals, the problem i've been having is if a file exists how to I skip. Could you put this in??
Ta
-
Jan 2nd, 2004, 05:19 AM
#16
-= B u g S l a y e r =-
Originally posted by Chrispybee
Ok guys & Gals, the problem i've been having is if a file exists how to I skip. Could you put this in??
Ta
-
Jan 24th, 2004, 07:59 AM
#17
Thread Starter
Supreme User
-
Jan 24th, 2004, 10:41 AM
#18
Originally posted by Madboy
Just keeping everyone up to date,
Not everybody backtrack threads you know
Have you read the first thread in this forum which says "In order to avoid duplicating something that is already in the Codebank, please do a search before posting." In other words DON'T "[keep] everyone up to date".
-
Jan 24th, 2004, 10:42 AM
#19
Thread Starter
Supreme User
Sorry, this post is ancient, i know better now
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
|