file coding

  • Thread starter Thread starter me
  • Start date Start date
M

me

I need to check for the existance of a file using VBA.

I am not sure how to check for this.

The file would reside on the local "c" drive.

Any help appreciated.

Dave
 
Dave:

You need to search the whole c drive?

If you are working with Access 9 or above, the following from MSDN might be
of help:


--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

---------------------------
The FileSearch object is a member of the Microsoft Office 9.0 Object
Library. It exposes a programmatic interface to all the functionality of the
Office File Open dialog box, including the features found in the Advanced
Find dialog box, which is available from the Open dialog box. You can use
the objects, methods, and properties of the FileSearch object to search for
files or collections of files based on criteria you supply.

The following example shows how to use the FileSearch object to find one or
more files of the type specified in the strFilespec argument. Notice that
you can search for multiple file extensions by specifying those extensions
as a semicolon-delimited list:

Function CustomFindFile(strFileSpec As String)
' This procedure demonstrates a simple file-search
' routine that displays a message box containing the
' names of all files in the "c:\" directory that
' match the file specifications provided in the
' strFileSpec argument.
' The strFileSpec argument can contain one or more file
' specifications in a semicolon-delimited list. For example, the
' following strFileSpec argument will return all files
' in the "c:\" that contain these extensions: "*.log;*.bat;*.ini"

Dim fsoFileSearch As Office.FileSearch
Dim varFile As Variant
Dim strFileList As String

' If the input in valid, then process the file search.
If Len(strFileSpec) >= 3 And InStr(strFileSpec, "*.") > 0 Then
Set fsoFileSearch = Application.FileSearch
With fsoFileSearch
.NewSearch
.LookIn = "c:\"
.FileName = strFileSpec
.SearchSubFolders = False
If .Execute() > 0 Then
For Each varFile In .FoundFiles
strFileList = strFileList & varFile & vbCrLf
Next varFile
End If
End With
MsgBox strFileList
Else
MsgBox strFileSpec & " is not a valid file specification."
Exit Function
End If
End Function
The FileSearch object has two methods and several properties that you can
use to build custom file-searching functionality into your custom Office
solutions. The previous example uses the NewSearch method to clear any
previous search criteria and the Execute method to carry out the search for
the specified files. The Execute method returns the number of files found,
and also supports optional parameters that let you specify the sort order,
the sort type, and whether to use only saved Fast Find indexes to perform
the search. You use the FoundFiles property to return a reference to the
FoundFiles object that contains the names of all matching files found in
your search.

You specify the directory to search by using the LookIn property, and you
use the SearchSubFolders property to specify whether the search should
extend to subfolders of the directory specified in the LookIn property. The
FileName property supports wildcard characters and a semicolon-delimited
list of file names or file-type specifications.



me said:
I need to check for the existance of a file using VBA.

I am not sure how to check for this.

The file would reside on the local "c" drive.

Any help appreciated.

Dave




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
Back
Top