Cross-platform file paths

U

utabintarbo

Until now, I have used the UNC under Windows (XP) to allow my program
to access files located on a Samba-equipped *nix box (eg.
os.path.normpath(r"\\serverFQDN\sharename\dir\filename")). When I try
to open this file under Linux (Red Hat 5), I get a file not found
error.

Is there a cross-platform method for accessing files on a network
share using Python 2.X?

TIA
 
C

cassiope

Until now, I have used the UNC under Windows (XP) to allow my program
to access files located on a Samba-equipped *nix box (eg.
os.path.normpath(r"\\serverFQDN\sharename\dir\filename")). When I try
to open this file under Linux (Red Hat 5), I get a file not found
error.

Is there a cross-platform method for accessing files on a network
share using Python 2.X?

TIA

normpath will convert forward slashes to backslashes on WinXX systems,
but
does not seem to do the reverse on posix systems...so try changing
your
string to use forward slashes. Also- is the path otherwise the same
on
your Linux system?

HTH..
-f
 
U

utabintarbo

normpath will convert forward slashes to backslashes on WinXX systems,
but
does not seem to do the reverse on posix systems...so try changing
your
string to use forward slashes.  Also- is the path otherwise the same
on
your Linux system?

HTH..
  -f

I tried forward slashes:

lst_p = open(os.path.normpath('//serverFQDN/sharename/dir/
filename'),'r').readlines()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '//serverFQDN/sharename/
dir/filename'

BTW, this works on WinXP.

It is as if it does not resolve, yet I have '//serverFQDN/sharename'
mounted, proving that it does resolve. Is this an issue with the way
python deals with the network? It does not seem like a network-only
issue.
 
N

News123

Hi TIA,
Until now, I have used the UNC under Windows (XP) to allow my program
to access files located on a Samba-equipped *nix box (eg.
os.path.normpath(r"\\serverFQDN\sharename\dir\filename")). When I try
to open this file under Linux (Red Hat 5), I get a file not found
error.

Is there a cross-platform method for accessing files on a network
share using Python 2.X?

Up to my knowledge there is now path name under linux, which gives you
access to samba shares without mounting then.


Perhaps there's some special user space file system drivers providing
that functionality, but I don't expect it to be standard linux behaviour.

What is your linux distribution?

I would suggest to change the subject line to something like:

"accessing samba shares from a linux host without mounting them"

or "cross-platform liibrary to access samba shares"
 
W

Wolfgang Rohdewald

No. On Linux, you need to mount the share in some empty
directory (using mount or smbmount), then read the files from
that directory.

actually the mount directory does not have to be empty - whatever
it contains is invisible while someting is mounted in it. But
of course using an empty directory gets you less surprises.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top