How can know whether file exists

How can I know whether file exists or not on the particular folder?
I know the "FileExists" method of the FileSystemObject.
But have to input obvious filename as the argument.
Could anyone who know let me know?
Thank you.

I'm a senior programmer.
Working at CamSight, Dental imaging solutions industry.
[336 byte] By [Jeong] at [2007-11-15 16:17:20]
# 1 Re: How can know whether file exists
many ways to do it but the most basic is with Dir$

if Dir$("c:\mydir\myfile.ext") <> "" Then (file exists)
makai at 2007-11-10 0:59:02 >
# 2 Re: How can know whether file exists
'here is a way to loop through a folder and enumerate files
'Warning: I did not test with subfolders
option Explicit

private Sub Command1_Click()
Dim lngX as Long
Dim fso as FileSystemObject
set fso = new FileSystemObject
Dim fls
Dim fc
With fso
set fls = .GetFolder(Dir1.Path) 'I used a dirlistbox to provide the path
'you may provide the string in a different way
set fc = fls.Files

Dim mx as Variant
for Each mx In fc
lngX = lngX + 1
next
End With
set mx = nothing
set fls = nothing
set fso = nothing
MsgBox "Number of files founded= " & lngX
End Sub

private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make dev-archive
a great place.
Come back soon, you Gurus.
Cimperiali at 2007-11-10 1:00:05 >
# 3 Re: How can know whether file exists
option Explicit

private Sub Command1_Click()
Dim lngX as Long
Dim fso as FileSystemObject
set fso = new FileSystemObject
Dim fls
Dim fc
With fso
set fls = .GetFolder(Dir1.Path) 'I used a dirlistbox to provide the path
'you may provide the string in a different
way
set fc = fls.Files

Dim mx as Variant
for Each mx In fc

lngX = lngX + 1
exit for
next
End With
set mx = nothing
set fls = nothing
set fso = nothing
if lngX > 0 then
'at least 1 file is in
else
'empty folder
end if
End Sub

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make dev-archive
a great place.
Come back soon, you Gurus.
Cimperiali at 2007-11-10 1:01:11 >
# 4 Re: How can know whether file exists
The contents that you suggested to me is in the case that I know the obvious file name.
How can I know whether file exists on particular folder in case I know only folder name but file name?

I'm a senior programmer.
Working at CamSight, Dental imaging solutions industry.
Jeong at 2007-11-10 1:02:09 >
# 5 Re: How can know whether file exists
The following will look at a folder and if any fiels exist in it, will enumerate them to the Debug window.

private Sub Command1_Click()
Dim str as string
str = Dir("C:\My Documents\*.*", vbNormal + vbReadOnly + vbSystem + vbHidden)
If str = "" then
MsgBox "No files exist in this folder"
else
' Enumerate the files in the Folder
Do Until str = ""
Debug.print str
str = Dir
Loop
End If
End Sub

John G
John G Duffy at 2007-11-10 1:03:08 >