Hi,
Two other solutions are:
This one courtesy of Randall Rath:
Question
What in your opinion is the best way to check to see if a file exists in a
folder
The Common Answer:
Private Function DoesFileExist(strFnamePath As String) As Boolean
strFnamePath = Dir(strFnamePath)
If strFnamePath = "" Then
DoesFileExist = False
Else
DoesFileExist = True
End If
End Function
The Secret Answer:
The API provides an UNDOCUMENTED method. Place this code In a standard
module:
Declare Function PathFileExists Lib "shlwapi" Alias _
"PathFileExistsA" (ByVal strFile As String) As Long
Public Function FileExists(strFile As String) As Boolean
FileExists = PathFileExists(strFile)
End Function
End of Randall's information:
The next lot I found on the web, but did not document the source:
Find File quickly
Public Const MAX_PATH = 400
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function FindFirstFile _
Lib "kernel32" _
Alias "FindFirstFileA" ( _
ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) _
As Long
Function FileExists(spFileSpec As String) As Boolean
Dim lFind As Long
Dim sSpec As String
Dim lpFind As WIN32_FIND_DATA
lFind = FindFirstFile(sSpec, lpFind)
If FindFirstFile(spFileSpec, lpFind) > 0 Then FileExists = True
End Function ' FileExists
My test call to the above:
Sub testfindfile()
Dim sSpec As String
sSpec = "C:\Program Files\CADApps\Linzlink\Settings\Table
Schemas\x_targetpoint.xsd"
'lFind = FindFirstFile(sSpec, tInfo)
If FileExists(sSpec) Then Debug.Print sSpec
End Sub
--
Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5450855@discussion.autodesk.com...
[code]
Function oFile(sFile As String) As Object
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set File = fs.GetFile(sFile)
Set fs = Nothing
End Function
Function oFile2(sFile As String) As File
'This one with early binding will require a reference
'to Microsoft Scripting Runtime
'But now you have intellisense
Dim fs As Scripting.FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
Set File = fs.GetFile(sFile)
Set fs = Nothing
End Function
[/code]