Question

How to delete a folder and all it's contents when you don't know the filenames ahead of time?

  • 19 August 2021
  • 3 replies
  • 43 views

Badge +8

The only related transformer I've been able to locate so far is FileDeleter and it requires knowing each and every file name ahead of time, and doesn't work at all on folders.


https://hub.safe.com/publishers/sigtill/transformers/filedeleter


3 replies

Badge +16

I would suggest using a Python caller with the shutil module to remove the folder directory and it's contents if you are familiar with Python.

https://docs.python.org/3/library/shutil.html#shutil.rmtree

 

import fme
import fmeobjects
import shutil
 
def deleteFolder(feature):
    shutil.rmtree(r"<path to folder>")

 

FME and Python

https://community.safe.com/s/article/python-and-fme-basics

 

Badge +8

I would suggest using a Python caller with the shutil module to remove the folder directory and it's contents if you are familiar with Python.

https://docs.python.org/3/library/shutil.html#shutil.rmtree

 

import fme
import fmeobjects
import shutil
 
def deleteFolder(feature):
    shutil.rmtree(r"<path to folder>")

 

FME and Python

https://community.safe.com/s/article/python-and-fme-basics

 

Oh. Has me wondering if I should just forego FME and do the whole thing in python (for this particular task).

 

Why import fme and fmeobjects if only shutil is being used?

Badge +16

Oh. Has me wondering if I should just forego FME and do the whole thing in python (for this particular task).

 

Why import fme and fmeobjects if only shutil is being used?

Importing fme and fmeobjects lets you use FME's classes and methods. It isn't necessary to import fme and fmeobjects in this example though as it will still remove the directory and it's contents without them.

Reply