Question

I'm building a system of apps that listen for files dumped into a folder shared on a smb shared drive. I've mounted the smb drives to the machine, shouldn't I be able to do a simple file.open()?

  file = open("//drive/location/of/file/file.txt")
  lines = file.readlines()
  for line in lines:
       print line
  file.close()

I'm on a Mac with Snow Leopard, I must admit that I am more used to windows development so I just may be misunderstanding something. Any help would be very appreciated.

I've seen a couple similar stack overflow questions such as this one Using pysmbc to read files over samba

But these are about connecting programmatically, I already have the drive mapped to my machine.

Was it helpful?

Solution

If the remote SMB drive is mounted, then it'd essentially be "part" of your main file system, and it'd just be

/path/to/mount_point/path/on/remote/server/file.txt
^^^^^^^^^^^^^^^^^^^^- local on mac
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- remote on other machine

and would all be considered "local", until file.txt is accesed, at which point the SMB infrastructure takes over and redirects the file operations to the remote machine.

Using the // notation indicates you're trying to reach directly over the network, and the format would be

//name_of_remote_machine/name_of_share/path/to/file.txt

with this, the localfile system is not involved, and all operations are immediately handled by the SMB system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top