getting filename cross platform
I have a file upload form which gets a filename from the local file system and then passes it to a Python Script which adds the file to the Zope filesystem and returns the filename. I want to return just the filename with the local path information stripped off. This works fine when the file is uploaded from Linux, but not when it is uploaded from Microsoft Windows. Here is the python script ## Script (Python) "add_to_filesystem_py" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=folder_name,file_name ##title= ## REQUEST = container.REQUEST RESPONSE = REQUEST.RESPONSE idFolder = getattr(context.Patients, REQUEST.get('pid')) folder = getattr(idFolder, folder_name) folder.manage_addFile(id='', file=file_name) return getattr(file_name, 'filename') If pid, the patient id, is '1234', folder_name is 'images' and file_name is '/some/path/to/somefile.dat' this will add '1234/images/somefile.dat' to the Zope filesystem and return 'somefile.dat'. But in windows if file_name is ' 'C:\some\path\to\somefile.dat', the same file will be added to the Zope filesystem but the entire filename with path will be returned. I think this is related to the id/title distinction. In the manager interface, the linux files are listed as somefile.dat (somefile.dat) and the microsoft files are listed as somefile.dat (C:\some\path\to\somefile.dat) So it appears that it is the title that is being returned when I want to the Id. Any suggestions on how I can modify my script to return the Id of the newly created File object? Thanks, John Hunter
participants (1)
-
John Hunter