Dir Function

W

Warrio

Hello

I am using the Dir function to see if the path that I have is still valid.

It works perfectly if the path begins with a drive, but when I try with a
file stored on a server or on internet, it can't work and shows the error
message "Bad file name or number".

if Dir("http://www.microsoft.com/myDoc.doc") = "" then MsgBox "File not
found!"

Is there something that I forgot or is there another way to make this check?

Thanks for any suggestion!
Best regards.
 
O

old man

Hi,

You can try mapping the network drive to a letter and then use dir against
the mapped drive. MS has s support note for using dir on a UNC file without
an extension (which a folder typically is) and MS suggest using the openfile
API to do so - the support note has a good example how to do so:

http://support.microsoft.com/kb/168519

You can also use an object called fso to check if a UNC folder exists. Karl
Peterson recently noted some of the issues involved in using FSO in VBA in
this forum but if used carefully can be a direct (non-api) solution to your
problem.

old man

old man
 
J

Jonathan West

Warrio said:
Hello

I am using the Dir function to see if the path that I have is still valid.

It works perfectly if the path begins with a drive, but when I try with a
file stored on a server or on internet, it can't work and shows the error
message "Bad file name or number".

if Dir("http://www.microsoft.com/myDoc.doc") = "" then MsgBox "File
not found!"

Is there something that I forgot or is there another way to make this
check?

Thanks for any suggestion!
Best regards.

Try this instead

http://vbnet.mvps.org/index.html?code/fileapi/fileexists.htm
 
O

old man

Hi,

By the way you want to use a UNC type notation which typically looks like
this:
\\server\dir\dir\file....

I would first try J. West's solution....

Old Man
 
W

Warrio

Hi Jonathan,
Thanks for your answer!

I tried the function you advised me, but unfortunately it doesn't work...
When I try it with an intranet file beginning with an "http://", it return
FALSE.
but when I try to open it "manually" with Word, the file is successfully
opened after a small window saying "Conneting to web server ..."

maybe this window is taken as an error by the function FindFirstFile...

Thanks again
 
R

Russ

Intranet ( within one network ) file usually begins with file://
Internet ( between networks ) file usually begins with http://

Can you prefix the url with file:// and try it?
 
W

Warrio

I don't have access because of the company's policies... with file://

(and it's an intranet (LAN) even if it starts with http:// you can have
hyperlinks even on not connected computer...)

but file doen't solve my problem..
Thanks anyway!
 
J

Jonathan West

Warrio said:
Hi Jonathan,
Thanks for your answer!

I tried the function you advised me, but unfortunately it doesn't work...
When I try it with an intranet file beginning with an "http://", it return
FALSE.

It would. It is inly intended to work with files on a local drive, a mapped
network drive or with a UNC path.
but when I try to open it "manually" with Word, the file is successfully
opened after a small window saying "Conneting to web server ..."

That is because the file is being downloaded into your temp folder and then
opened by Word. Witrh that downloaded file open, go to the immediate window
in the VBA editor and type the following

? ActiveDocument.Fullname

You will find the location of the doc on your local drive.

If you want to find whether an http url exists, then you need a different
approach, possibly using the Windows API function InternetConnect. I'm not
an expert in this area but if you do a search for that function you will
probably find something.
 
W

Warrio

Thanks a lot for your help!


Jonathan West said:
It would. It is inly intended to work with files on a local drive, a
mapped network drive or with a UNC path.


That is because the file is being downloaded into your temp folder and
then opened by Word. Witrh that downloaded file open, go to the immediate
window in the VBA editor and type the following

? ActiveDocument.Fullname

You will find the location of the doc on your local drive.

If you want to find whether an http url exists, then you need a different
approach, possibly using the Windows API function InternetConnect. I'm not
an expert in this area but if you do a search for that function you will
probably find something.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
 
K

Karl E. Peterson

OP was asking about an HTTP location. I don't believe FSO works any differently
than any other file/folder-based solution for this sort of test, does it?
 

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