Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard for FileName

Status
Not open for further replies.

ter79

IS-IT--Management
Jul 11, 2001
106
US
I have the following code that I'm using to see if any files with the .txt extension exists. When I run the code it keeps coming back that the file does not exists when in there is a .txt file in the directory.

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\CABC Mailing Lists\Outbound\*.txt") Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If


What am I doing wrong? Thanks in advance!
 
The method you are calling does not support wildcards. It requires the exact path of a specific file. The code below should get you moving foward again.

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.getfolder("C:\CABC Mailing Lists\Outbound")
For Each File in Folder.Files
If fso.GetExtensionName(File)="txt"Then
MsgBox "File Exists"
Found=vbTrue
End If
Next
If Found<>vbTrue Then MsgBox &quot;File Does Not Exist&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top