Question

Does a File Exist?

  • 9 September 2013
  • 4 replies
  • 79 views

Badge
I'm trying to determine if a dataset, one of many, has already been processed so my workspace won't repeat that dataset but rather move on to the next dataset.  If the dataset has been done there will be file that I can test for. 

 

 

If I use AttributeFileReader on an existing file it is OK but if the file doesn't exist it halts the workspace.

 

 

I can check using a PythonCaller but can't pass the result back to the workspace to use in a tester transformer.

 

 

Any help would be much appreciated,

 

Alan

4 replies

Userlevel 4
Hi,

 

 

it is quite easy to set an attribute using a PythonCaller:

 

 

doesFileExist = os.path.exists(file_path)

 

feature.setAttribute("FILE_EXISTS", doesFileExist)

 

 

You can then expose the attribute FILE_EXISTS in the workspace and use it in your Tester.

 

 

David
Badge
Almost too easy.  Thanks David.
Badge +4

@david_r How might you suggest I check if a file exists on an FTP server directory?

For instance:

  • If file.zip exists in ftp://google.com/dir/file.zip

     

    • Then create copy of file.zip on C:\\temp\\file.zip

I'm trying to prevent FME from writing an empty ZIP file on my local drive when the FTPCaller does not find a ZIP file within the remote directory.

Currently, even when the FTPCaller errors out, it still creates the empty ZIP file when set to 'Download to a file'.

Userlevel 2
Badge +17

Hi @dmatranga, currently there seems to be no way to prevent creating the empty zip file when the downloading failed. There may be two approaches to resolve the annoying.

  1. Remove the empty zip file if the downloading failed - maybe need to write a script.
  2. Save the download file as a temporary file, and move it to the specified path only when the downloading was successful.

This screenshot illustrates an example for the second approach. The temporary file which was generated with the TempPathnameCreator will be deleted automatically when the translation has completed, if it still exists there.

Hope this helps.

Reply