Skip to main content

Hi,

I have a workspace that uses the custom FeatureCounter followed by a TestFilter. If too many features for my conversion I port to a Terminator transformer.

Following termination I want to delete the input file as part of a Python Shutdown script. The path including filename are in a Published Parameter. Example: [source_file]: c:\\folder\\file.ext

I've looked at lots of info but my attempts produce errors or the file doesn't get deleted, or both.

Can someone with good experience with this provide details on all lines needed in the shutdown script (and if needed, any Python needed in the body of the workspace)?

Thanks!

You can try the following in your shutdown script:

import fme
import os

if not fme.status:
    os.remove(fme.macroValues('source_file'])

This will delete the file referenced in the parameter "source_file" if the workspace failed, e.g. with a Terminator.


Thanks @david_r, indeed that worked. Oddly I still got an error with your code. In the end, the issue had to do with the "type" of the published parameter that holds the filename (that parameter was created by someone else). So I re-created the parameter as a text type, and that made both the FeatureReader and the exit script Python happy. 

Below I'm including the error I got prior to re-creating the parameter, in case the same thing happens to anyone else. That issue with the parameter type took far too much time to track down, believing the problem had to do with a mistake in my use of the Python in the shutdown script.

FME_END_PYTHON: evaluating python script from string...
END - ProcessID: 16548, peak process memory usage: 185908 kB, current process memory usage: 82432 kB

Python Exception <WindowsError>: ÂError 123] The filename, directory name, or volume label syntax is incorrect: 'c:<backslash>folder<backslash>roger<backslash>file.ext'
Error executing string `import fme
import os
if not fme.status:
    os.remove(fme.macroValues&'source_file'])
'
FME_END_PYTHON failed to execute provided script

Terminator_5: Termination Message: 'Translation Terminated due to too many features in file'
Program Terminating

Translation FAILED.

Thanks again.


Reply