473,236 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

URI IsFile

Hi there,

The following returns "False"...

MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)

Is there any particular reason? It seems like a pretty poor function to
me as that is without a doubt an URI to a file...

Are there any other ways of detecting if this is a file reliably?

Thanks in advance.

Nick.
Jun 15 '06 #1
6 3295
Nick,
| Is there any particular reason? It seems like a pretty poor function
to
| me as that is without a doubt an URI to a file...
Your URI is without a doubt an FTP URI, not a File URI!

A file URI uses the "file" scheme, your uri is using the "ftp" scheme.

http://msdn2.microsoft.com/en-us/lib...me(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...le(VS.80).aspx

Try:

| MsgBox(New Uri("file://me.pop.com/pop.bmp").IsFile.ToString)
| Are there any other ways of detecting if this is a file reliably?
What do you mean by "a file"?

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"NickP" <a@a.com> wrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
| Hi there,
|
| The following returns "False"...
|
| MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)
|
| Is there any particular reason? It seems like a pretty poor function
to
| me as that is without a doubt an URI to a file...
|
| Are there any other ways of detecting if this is a file reliably?
|
| Thanks in advance.
|
| Nick.
|
|
Jun 15 '06 #2
"NickP" <a@a.com> schrieb:
The following returns "False"...

MsgBox(New Uri("ftp://me.pop.com/pop.bmp").IsFile.ToString)

Is there any particular reason?
Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns
'True' if the URI's scheme is "file" ('Uri.UriSchemeFile').
Are there any other ways of detecting if this is a file reliably?


Not really, because an URI doesn't contain any information about the type of
resource it is referring to.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #3
Hi Jay,
A file URI uses the "file" scheme, your uri is using the "ftp" scheme.
Hmm, that just seems like a waste of a function to be honest. If all it
is doing is checking for a "file://" protocol then that feature is already
available via.

MsgBox(New
Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
MsgBox(New
Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
| Are there any other ways of detecting if this is a file reliably?
What do you mean by "a file"?


i.e. not just a path like

http://www.mysite.com/pop/
http://www.mysite.com/pop/pants/
http://www.mysite.com/pop/pants/foobar/

more like

http://www.mysite.com/pop/pants/myfile.html
http://www.mysite.com/pop/pants/football/myfile2.html

I've resorted to checking for a trailing backslash on the absolute path.
If it's not then it's presumed to be a file. Although this is not ideal it
is working for what I currently want it for.

Cheers for clearing that up for me anyway.

Nick.
Jun 15 '06 #4
Hi Herfried,
Yes! Did you read the documentation for 'Uri.IsFile'? 'IsFile' returns
'True' if the URI's scheme is "file" ('Uri.UriSchemeFile').
Yeah it just didn't seem to make sense if you could perform the check
manually anyway...

MsgBox(New
Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
MsgBox(New
Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
Not really, because an URI doesn't contain any information about the type
of resource it is referring to.


:-( Oh well, thanks for the help anyway.

Nick.
Jun 15 '06 #5
"NickP" <a@a.com> schrieb:
| Are there any other ways of detecting if this is a file reliably?
What do you mean by "a file"?


i.e. not just a path like

http://www.mysite.com/pop/
http://www.mysite.com/pop/pants/
http://www.mysite.com/pop/pants/foobar/

more like

http://www.mysite.com/pop/pants/myfile.html
http://www.mysite.com/pop/pants/football/myfile2.html

I've resorted to checking for a trailing backslash on the absolute
path. If it's not then it's presumed to be a file. Although this is not
ideal it is working for what I currently want it for.


Hm... The trailing backslash indicates that the directory's default
document (which is often a file) should be returned, at least for common
HTTP servers.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 15 '06 #6
| MsgBox(New
| Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
Yes one could, however if you are checking IsFile in a number of places,
that is a lot of duplicated code.

Further IsFile feels like an attribute of Uri, while UriSchemeFile feels
more like an implementation detail.
To understand the smell of duplicated code see Refactoring by Martin Fowler:

http://martinfowler.com/books.html#refactoring

http://www.refactoring.com/
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"NickP" <a@a.com> wrote in message
news:eD**************@TK2MSFTNGP03.phx.gbl...
| Hi Jay,
|
| > A file URI uses the "file" scheme, your uri is using the "ftp" scheme.
|
| Hmm, that just seems like a waste of a function to be honest. If all
it
| is doing is checking for a "file://" protocol then that feature is already
| available via.
|
| MsgBox(New
| Uri("ftp://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << false
| MsgBox(New
| Uri("file://pop.com/pop.bmp").Scheme.Equals(Uri.UriSchemeFile)) << true
|
| > | Are there any other ways of detecting if this is a file reliably?
| > What do you mean by "a file"?
|
| i.e. not just a path like
|
| http://www.mysite.com/pop/
| http://www.mysite.com/pop/pants/
| http://www.mysite.com/pop/pants/foobar/
|
| more like
|
| http://www.mysite.com/pop/pants/myfile.html
| http://www.mysite.com/pop/pants/football/myfile2.html
|
| I've resorted to checking for a trailing backslash on the absolute
path.
| If it's not then it's presumed to be a file. Although this is not ideal
it
| is working for what I currently want it for.
|
| Cheers for clearing that up for me anyway.
|
| Nick.
|
|
Jun 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gonnasi | last post by:
With >glob.glob("*") or >os.listdir(cwd) I can get a combined file list with directory list, but I just wanna a bare file list, no directory list. How to get it? Tons of thanks in advance!
1
by: Flix | last post by:
Is there any function to detect if a valid path is a file or a directory ? I've tried with (System.IO.Path.GetExtension(path)==""), but it doesn't work, since some files haven't any extension and...
7
by: C. A. Kelly | last post by:
I have a program that I want to launch links if certain criteria is met, the problem is how can I determine if a string is a program to launch, here is an example with quotes-> "c:\Program...
1
by: Gary Wessle | last post by:
Hi could someone help me to find out whats wrong with this code? **************** code **************** import os, sys if len(sys.argv) < 2: sys.exit("please enter a suitable directory.")
5
by: 7stud | last post by:
Here's the code: ------------ import os, os.path, pprint mydir = "/Users/me/2testing" files = pprint.pprint(files) print os.path.join(mydir, "helloWorld.py")
10
by: ppaterson | last post by:
Can os.path.isfile(x) ever return True after os.remove(x) has successfully completed? (Windows 2003, Python 2.3) We had a couple of failures in a server application that we cannot yet reproduce...
2
by: 7stud | last post by:
Here is a program to print out the files in a directory: ----------- import os myfiles = os.listdir("../") print myfiles for afile in myfiles: print afile
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.