Skip to main content
Question

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


mattwilkie
Supporter
Forum|alt.badge.img+11

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

warrendev
Enthusiast
Forum|alt.badge.img+24
  • Enthusiast
  • August 18, 2021

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

 


mattwilkie
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • August 19, 2021
warrendev wrote:

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?


warrendev
Enthusiast
Forum|alt.badge.img+24
  • Enthusiast
  • August 19, 2021
mattwilkie wrote:

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.


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