Skip to main content
Hi Folks,

 

I want my workspace to clean up after itself. It creates a number of files in a temporary location, which is specified in a parameter: FANOUT_DIRECTORY], which points to:

 

 

C:\\TempData\\translation_temp

 

 

Using FME 2014, I want to get python to delete all fines within this.

 

 

In theory, I need something like this:

 

 

#remove the text files

 

import os;

 

def FeatureProcessor(feature):

 

folder = str(FME_MacroValues_'FANOUT_DIRECTORY'])

 

 

for the_file in os.listdir(folder):

 

  file_path = os.path.join(folder, the_file)

 

  try:

 

   if os.path.isfile(file_path):

 

    os.unlink(file_path)

 

  except Exception, e:

 

   print e

 

However, the value for "folder" when it gets the parameter FANOUT_DIRECTORY is:

 

 

C:<backslash>TempData<backslash>translation_temp

 

 

Which is obviously wrong. Anyone know how to get a parameter properly such that I can just use it? The examples I've seen don't appear to have this problem (but Python-FME documentation is sparse and conflicting).

 

 

Thanks.
Hi,

 

 

there are several solutions to this, but the easiest is perhaps:

 

 

folder = str(FME_MacroValuesl'FANOUT_DIRECTORY']).replace('<backslash>', '\\\\')

 

 

David
Btw, starting with FME 2014, you can also use the following method from the fmeobjects API:

 

 

folder = fmeobjects.FMESession().decodeFromFMEParsableText(FME_MacroValuese'FANOUT_DIRECTORY'])

 

 

(If I'm not mistaken...)

 

 

David
Hi David,

 

Thanks, the second one works like a charm!

Reply