Python to Retrieve list of file on a Network Folder

Is is possible to have a gateway function to retrieve a list of file names and/or folders within a networked dive the gateway has access to?

Sure! Since you didn’t say what OS the share is on, I’m going to assume Windows

[code]def filelist(path):
from os import walk

f = []
d = []

for (dirpath, dirnames, filenames) in walk(path):

return [f, d]

print filelist(’//pcName/shareName/folder’)

You can remove the break if you need to recurse into subdirectories, but it’ll take more time to finish if it’s very deep.

For example, let’s say the share is called “mothra” and resides on the server “gamera”. The folder to want a listing of is in “/production/reports”. Your path to use would be “//mothra/gamera/production/reports”

Ok I am find that if try to use any of the


or any other ‘os’ function it will always report back from the view of the client. even if i have the following in a project gateway script.

def ImageSearch()
import os
dir = os.listdir(’\Z:\’)
return dir

and call it from the script playground it will always retun the list from the client pc. Why is this?

[quote=“jmoniz”]… call it from the script playground it will always retun the list from the client pc. Why is this?[/quote]Because it’s in a client. {Designers are clients, too.} Only scripts run from a gateway event will actually run in the gateway environment. Errors from those scripts show up in the gateway console, not in any client. Even if you are developing on the gateway server, the gateway service is separate from the user logged in.


As an exercise, create two memory tags in the gateway: a boolean ‘trigger’ and a string ‘result’. Define a value change event on the ‘trigger’ tag with: if not initialChange: from java.util import Date import os x = os.listdir("//someserver/someshare/path") system.tag.write("[default]result", str(x)) Then toggle the trigger tag. Look at the result.

Um i forgot to add that code was in a gateway script but i was calling the function from a client

Problem fixed.

Talked to support over the phone.

The issue was a user account issue trying to access a network share using a windows mapped drive. the path to the share needed to be explicit.

path = '\\\sharename\folder"


path = “\Z:\sharename\folder”