Dir function oddity

  • Thread starter Thread starter GPO
  • Start date Start date
G

GPO

Access 2000
I am a sometime VBA dabbler trying to help a complete non-
programmer over the phone with a problem that does not
make sense to me (I can see we're off to a great start).
The following snippet is supposed to take a path and file:
(eg PathAndSelectedFile = "C:\Data\XXXXXXXa.txt")
and yeild a filename:
(eg FileToLoad = "XXXXXXXa.txt").

FileToLoad = _
Dir(Left(PathAndSelectedFile, _
Len(PathAndSelectedFile) - 5) & "?.txt", _
vbNormal)

It ALWAYS works properly on my pcs (Win 98, Win 2000, Win
XP), but my friend is adamant that it is yeilding the full
path and file (eg "C:\Data\XXXXXXXa.txt"), which is not
what we want.
Because I can't replicate it, I'm becoming a little
skeptical, but I would be grateful if someone could
confirm that this is a normal behaviour of Dir() and what
we can do to guarantee that we will only get the file and
not the path.

(Incidentally the "?.txt" is a wild card to find any file
named the same as the file in the PathAndSelectedFile
variable except for the fifth last char)

Regards

GPO
 
I don't have Access here to check, but I am fairly sure that Dir() does not
return the path.

If your friend is a "complete non-programmer", he is probably just mistaken
about the value returned. How is he checking that value? Has he put a msgbox
immediately after the FileToLoad=.. statement? My bet is: no. He is getting
the value from somewhere else - so it does not necessarily reflect what is
returned by the statement in question.

HTH,
TC
 
I'm doing the message box trick and getting her to write
down what it brings up. I'll let you know what we find.

Many thanks

GPO
 
Hi:

Dir just returns the file name (no path) if file exists.

For example in debug window type --

?Dir("C:\autoexec.bat")
you will get "autoexec.bat" if it exists.

Regards,

Naresh Nichani
Microsoft Access MVP
 
Back
Top