Dir("D:\") refresh problem

A

Alex St-Pierre

Hello,
The Dir function doesn't work all the time
example:
If Dir("D:\temp\alex\") = "" Then
exit sub
endif
the macro doesn't stop because the repertory is valid

and then, I try:
If Dir("D:\temp\") = "" Then
exit sub
endif
and the macro stop ?

It's very strange, the drive used is a server drive but always available.

Finally, I tried:
path = "D:\temp\"
ChDrive path
ChDir path
If Dir(path) = "" Then
exit sub
endif
ChDrive and ChDir change but the macro stop ??
Any idea ?
Thanks,
 
J

Jake Marx

Hi Alex,

If you don't specify that you're looking for a directory, Dir() will return
the name of the first file found in that folder. So in this case, I'm
assuming that D:\temp\alex\ contains at least one file and that D:\temp\
only contains folders.

You could use this instead:

If Len(Dir$("D:\temp\alex\", vbDirectory)) Then

and

If Len(Dir$("D:\temp\", vbDirectory)) Then


These statements should return True if the folders exist and False if they
don't exist.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
A

Alex St-Pierre

Thanks a lot, i used:
If Len(Dir$("D:\temp\", vbDirectory))=0 Then
end if
Jake Marx said:
Hi Alex,

If you don't specify that you're looking for a directory, Dir() will return
the name of the first file found in that folder. So in this case, I'm
assuming that D:\temp\alex\ contains at least one file and that D:\temp\
only contains folders.

You could use this instead:

If Len(Dir$("D:\temp\alex\", vbDirectory)) Then

and

If Len(Dir$("D:\temp\", vbDirectory)) Then


These statements should return True if the folders exist and False if they
don't exist.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Hello,
The Dir function doesn't work all the time
example:
If Dir("D:\temp\alex\") = "" Then
exit sub
endif
the macro doesn't stop because the repertory is valid

and then, I try:
If Dir("D:\temp\") = "" Then
exit sub
endif
and the macro stop ?

It's very strange, the drive used is a server drive but always
available.

Finally, I tried:
path = "D:\temp\"
ChDrive path
ChDir path
If Dir(path) = "" Then
exit sub
endif
ChDrive and ChDir change but the macro stop ??
Any idea ?
Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top