os.path.exists() function does not work for http paths

Steve Holden steve at holdenweb.com
Mon Sep 29 19:34:41 CEST 2008


dudeja.rajat at gmail.com wrote:
> Hi,
> 
> I have used os.path.exists() many a times for any file system paths in
> local system. But this does not seem to work for an Http path.
> 
> e.g:
> 
> 
> To check is the Results folder exists at the following path, I do:
> 
> 
> if not os.path.exists("http://subversion.myCom.com/Testing/Results"):
>     print 'Path does not exist'
> 
> 
> This always prints the above print statements whether or not the Results
> folder exists or not.
> 
> Is there any such function to check existence of files. / folder at Http
> paths?
> 
You could use one of the URL libraries. The os.path module is for
dealing with the local filesystem.

The absence of any exception from

  f = urllib.urlopen("http://www.google.com/webhp/")

is a good indication that the addressed page "exists" (but remember that
the web is a virtual address space, so it doesn't necessarily mean that
there's a real file or directory object behind ot).

regards
 Steve

-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list