views:

333

answers:

1

What is the best way to know if a network path(e.g. //192.168.1.1/test) exist using python in linux?

+1  A: 

If by "path" you mean an internet URL, you'll want to look at the urllib module.

from urllib import urlopen
try:
    urlopen(path)
except IOError:
    pass # does not exist
else:
    pass # does exist

If by "path" you mean a Windows UNC, then you'll want to use the os module.

import os
os.path.isdir(path)

Note, I've found the Windows UNC paths somewhat flakey. Depending on your network setup and permissions, they may or may not be accessible.

Chris S
Sorry for the confusion. What i want is that if a user enter a network path(a shared folder path), before going for further processing, i want to verify that if that path really exist or not?
MA1