|
-
Apr 19th, 2001, 08:46 PM
#1
Thread Starter
Lively Member
I actually had this post in the General forum thinking more people were gonna see it, however, no response.
Oh wells, here it goes again...
Is the FileExists method of the FileSystemObject the only way to check if a file exists? I heard that using the FileSystemObject uses a lot of system resources. Any feedback would be greatly appreciated. Thanks.
ttlai
-
Apr 19th, 2001, 11:48 PM
#2
PowerPoster
I would think that using the fileexists method is the only way, if not then any other way is going to be even slower.
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Apr 20th, 2001, 03:32 AM
#3
Retired VBF Adm1nistrator
You can use the Dir function.
Used only on its own it is faster than the filesystemobject because the filesystemobject must be created first.
But if you create the filesystemobject once, and then use the fileexists method in a loop it is faster.
In the speed comparison below I am creating the filesystemobject everytime I need it.
So if you only want to do a few files, use Dir(), but if you want to do loads of files, create the filesystemobject, and then use its fileexists method in a loop.
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim timeMethod1 As Long
Dim timeMethod2 As Long
Dim i As Long
Dim fs As Object
Private Sub Form_Load()
timeMethod1 = GetTickCount()
For i = 0 To 10000
Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.FileExists("c:\command.com")) Then
End If
Next i
timeMethod1 = GetTickCount() - timeMethod1
timeMethod2 = GetTickCount()
For i = 0 To 10000
If (Dir("c:\command.com") <> "") Then
End If
Next i
timeMethod2 = GetTickCount() - timeMethod2
MsgBox "Times Taken : " & vbCrLf & vbCrLf & "FileSystemObject : " & timeMethod1 & vbCrLf & "Dir Function : " & timeMethod2
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 20th, 2001, 04:24 AM
#4
Code:
Dim Fileexists as boolean
If len(dir$("C:\Path\File.exe")) <> 0 then Fileexists = true
The above looks at the length of the file. Using the Dir function, but as Jamie's put, if there are a lot of files to check, use the FileSystemObject.
-
Apr 20th, 2001, 04:25 AM
#5
Retired VBF Adm1nistrator
doo bee doo bee doo im not being followed at all ... doo bee doo ....
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 20th, 2001, 04:34 AM
#6
Just that the LEN(DIR$( option's faster than the Dir( option ...
-
Apr 20th, 2001, 04:39 AM
#7
Retired VBF Adm1nistrator
If the file exists it is
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 20th, 2001, 09:20 AM
#8
Thread Starter
Lively Member
thanks plenderj
i only need to check one file so i'm gonna go with the Dir() function
thanks again
ttlai
-
Apr 20th, 2001, 09:57 AM
#9
Retired VBF Adm1nistrator
I won. I won
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
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
|