Cross-platform file paths

Discussion in 'Python' started by utabintarbo, May 7, 2010.

  1. utabintarbo

    utabintarbo Guest

    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
     
    utabintarbo, May 7, 2010
    #1
    1. Advertising

  2. utabintarbo

    cassiope Guest

    On May 7, 7:32 am, utabintarbo <> wrote:
    > 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
     
    cassiope, May 7, 2010
    #2
    1. Advertising

  3. utabintarbo

    utabintarbo Guest

    On May 7, 11:23 am, cassiope <> wrote:
    >
    > 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.
     
    utabintarbo, May 7, 2010
    #3
  4. utabintarbo

    News123 Guest

    Hi TIA,

    utabintarbo wrote:
    > 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"
     
    News123, May 8, 2010
    #4
  5. On Sonntag 09 Mai 2010, Tim Roberts wrote:
    > 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.

    --
    Wolfgang
     
    Wolfgang Rohdewald, May 9, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    790
  2. mir nazim
    Replies:
    7
    Views:
    554
    Brian Kelley
    Nov 24, 2003
  3. Vlastimil Brom
    Replies:
    0
    Views:
    515
    Vlastimil Brom
    Mar 12, 2009
  4. Vlastimil Brom
    Replies:
    1
    Views:
    423
    David Smith
    Mar 13, 2009
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    201
    David Vallner
    Nov 7, 2006
Loading...

Share This Page