Example 2: allowing users to obtain directory or file information based on their privileges

To avoid the PSAPI being opened to users, a method called session.getServerFileSystem() can be used via calling the PSAPI function to create a file system object.

The following example shows how to allow a user to get directory or file information based on the privileges of the user that connects to the IBM® SPSS® Modeler Server.

import modeler.api
stream = modeler.script.stream()
sourceNode = stream.findByID('')
session = modeler.script.session()
fileSystem = session.getServerFileSystem()
parameter = stream.getParameterValue('VPATH')
serverDirectory = fileSystem.getServerFile(parameter)
files = fileSystem.getFiles(serverDirectory)
for f in files:
    if f.isDirectory():
        print 'Directory:'   
    else:
        print 'File:'       
        sourceNode.setPropertyValue('full_filename',f.getPath())
        break
    print f.getName(),f.getPath()
stream.execute()