Skip to main content
Question

How can I create an empty new folder with a prefix_ followed by current date time?

  • November 14, 2023
  • 1 reply
  • 99 views

Hello,

 

I am trying to create a folder with a prefix of Run_ and have the current datetime as the folder name. I am very new to FME and I am not sure what I am doing wrong with the setup that nothings gets created in the path I have as destination (screenshot below). I appreciate any help.

1 reply

dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • November 14, 2023

What is your input for the writer? If you don't have any features to feed into it currently, you can use the Creator transformer to create a feature. Also, you may want to read into the format attributes of the writer...filecopy_source_dataset and filecopy_dest_filename.

https://docs.safe.com/fme/html/FME-Form-Documentation/FME-ReadersWriters/filecopy/filecopy.htm

 

Alternatively, I usually use either a PythonCreator or PythonCaller when I need to create directories. The below code in a PythonCreator will create the Run_ folder, you will just need to update the dir variable to where you want the folder to be created. You can also link the dir to a published parameter in the code.

import fmeobjects
import os
from datetime import datetime
 
class FeatureCreator(object):
    """Template Class Interface:
    When using this class, make sure its name is set as the value of the 'Class
    to Process Features' transformer parameter.
    """
    
    def __init__(self):
        """Base constructor for class members."""
        dir = "E:\\your_path"
        new_dir = os.path.join(dir,"Run_"+datetime.now().strftime("%Y%m%d"))
        
        if not os.path.exists(new_dir):
            os.makedirs(new_dir)
       
        pass
        
    def input(self, feature):
        """This method is called once by FME to create FME Feature(s).
        A created Feature is emitted through the self.pyoutput() method.
        Any number of Features can be created and emitted by this method.
        
        :param fmeobjects.FMEFeature feature: Dummy FME Feature passed in by
            FME. It can be ignored.
        """
                
        newFeature = fmeobjects.FMEFeature()
        self.pyoutput(newFeature)
        
    def close(self):
        """This method is called at the end of the class."""
        pass

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings