Skip to main content
Solved

File Copy - DELETE


sigtill
Contributor
Forum|alt.badge.img+24

Is it possible to DELETE files using the WRITER "File Copy" ?

 

 

UPDATE:

I have created a custom transformer that uses the solution (FeatureWriter in MOVE to null) and uploaded to https://hub.safe.com/publishers/sigtill/transformers/filedeleter

Feel free to send any feedback related to this.

Best answer by sigtill

UPDATE: 2020:

This solution seems to be easier than the previous:

Replace the three variables needed (filecopy_XXX, XXX XXX) and the dest_filename to nul (with one l, not two ll). And make sure the FeatureWriter is set to MOVE

 

 

View original
Did this help you find an answer to your question?

15 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • May 19, 2015
Hi Sig,

 

 

I don't think it's possible, but it's easy to delete a file with a script. Assuming that an attribute called "filepath" stores the file path that should be deleted,

 

-----

 

# Example for PythonCaller

 

import os

 

def removeFile(feature):

 

    file = feature.getAttribute('filepath')

 

    if os.path.exists(file):

 

        os.remove(file)

 

-----

 

# Example for TclCaller

 

proc delFile {} {

 

    file delete [FME_GetAttribute "filepath"]

 

}

 

-----

 

 

Takashi

Forum|alt.badge.img
  • August 25, 2016
takashi wrote:
Hi Sig,

 

 

I don't think it's possible, but it's easy to delete a file with a script. Assuming that an attribute called "filepath" stores the file path that should be deleted,

 

-----

 

# Example for PythonCaller

 

import os

 

def removeFile(feature):

 

    file = feature.getAttribute('filepath')

 

    if os.path.exists(file):

 

        os.remove(file)

 

-----

 

# Example for TclCaller

 

proc delFile {} {

 

    file delete [FME_GetAttribute "filepath"]

 

}

 

-----

 

 

Takashi
@takashi How would you write this script to delete entire folders instead of files?

 

 


itay
Supporter
Forum|alt.badge.img+16
  • Supporter
  • August 25, 2016

@kam you could just use a system caller and an old fashion dos command for that


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 26, 2016

Hi @kam, the "os.rmdir(path)" method removes an empty folder; the "os.removedirs(path)" method removes a folder and its subfolders recursively if they all are empty; the "shutil.rmtree(path)" method removes a folder and all files and subfolders belonging to the specified folder. See the Python documentation to learn more.


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • August 26, 2016

You could use FileCopy and move the file to the null folder. \\dev\\null on Linux I think. There is a Windows equivalent, but I can't recall it off hand.


sigtill
Contributor
Forum|alt.badge.img+24
  • Author
  • Contributor
  • Best Answer
  • October 15, 2019

UPDATE: 2020:

This solution seems to be easier than the previous:

Replace the three variables needed (filecopy_XXX, XXX XXX) and the dest_filename to nul (with one l, not two ll). And make sure the FeatureWriter is set to MOVE

 

 


sigtill
Contributor
Forum|alt.badge.img+24
  • Author
  • Contributor
  • January 14, 2020

The most recent (and best solution) is to overwrite the 3 parameters: and set filecopy_dest_filename = nul (with one l, not 2 ll).

 


sigtill
Contributor
Forum|alt.badge.img+24
  • Author
  • Contributor
  • January 14, 2020

Forum|alt.badge.img
  • September 21, 2020

Is there anyone that have used FileDeleter from @Sigbjørn Herstad​ on FME Server? For me it works fine in Workbench but not on FME Server. The log files gives the same message but the file isn't deleted when running on the server. Both desktop and server runs on Windows OS. The server write to this files hare so there might not be an permission issue.

 

Log file:

2020-09-21 11:42:35| 0.7| 0.0|ERROR |File Copy Writer: Cannot create destination folder '\\'

2020-09-21 11:42:35| 0.7| 0.0|INFORM|File Copy Writer: Received move request from '\\\\fileshare1\\folder\\temp\\781af574-ea39-44f9-95d4-ea7f62e050fd.ffs' to 'c:\\temp\\\\\\nul'


sigtill
Contributor
Forum|alt.badge.img+24
  • Author
  • Contributor
  • September 21, 2020
keoe wrote:

Is there anyone that have used FileDeleter from @Sigbjørn Herstad​ on FME Server? For me it works fine in Workbench but not on FME Server. The log files gives the same message but the file isn't deleted when running on the server. Both desktop and server runs on Windows OS. The server write to this files hare so there might not be an permission issue.

 

Log file:

2020-09-21 11:42:35| 0.7| 0.0|ERROR |File Copy Writer: Cannot create destination folder '\\'

2020-09-21 11:42:35| 0.7| 0.0|INFORM|File Copy Writer: Received move request from '\\\\fileshare1\\folder\\temp\\781af574-ea39-44f9-95d4-ea7f62e050fd.ffs' to 'c:\\temp\\\\\\nul'

Unfortunately it does not work on FME Server. I would suggest to use a FeatureWriter and Move files to the $FME_SHAREDRESOURCE_TEMP folder. Then they will be deleted by FME Server in a given interval.


Forum|alt.badge.img
  • September 21, 2020
sigtill wrote:

Unfortunately it does not work on FME Server. I would suggest to use a FeatureWriter and Move files to the $FME_SHAREDRESOURCE_TEMP folder. Then they will be deleted by FME Server in a given interval.

Thank you for your support!


teason
Participant
  • Participant
  • October 1, 2020

Does this support using the fme_dataset attribute as the file to delete? Also, is it possible to put it after a FeatureWriter so basically I can delete the file after it has been processed?

 

Thanks.


klingdom
Contributor
Forum|alt.badge.img+5
  • Contributor
  • December 11, 2020

Hello, Can We use *.* with FileDeleter? If not that would be a suggestion for enhancement.


tim_wood
Contributor
Forum|alt.badge.img+8
  • Contributor
  • September 12, 2022
sigtill wrote:

UPDATE: 2020:

This solution seems to be easier than the previous:

Replace the three variables needed (filecopy_XXX, XXX XXX) and the dest_filename to nul (with one l, not two ll). And make sure the FeatureWriter is set to MOVE

 

 

I have been trying to use this method but it's not working. However I notice that you are setting a value for filecopy_dest_dataset although there is nothing in the Attribute Value. So are you setting the value to an empty string? I've been using a FeatureWriter to try and do this for *.png in a particular folder, and only specifying the values for filecopy_source_dataset and filecopy_dest_filename.

 

Or do I need to change some of these parameters?

File Copy Parameters


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • September 12, 2022
tim_wood wrote:

I have been trying to use this method but it's not working. However I notice that you are setting a value for filecopy_dest_dataset although there is nothing in the Attribute Value. So are you setting the value to an empty string? I've been using a FeatureWriter to try and do this for *.png in a particular folder, and only specifying the values for filecopy_source_dataset and filecopy_dest_filename.

 

Or do I need to change some of these parameters?

File Copy Parameters

I've not tried the nul method, i normally use a TempPathName creator, move the file to that location and then it's automatically deleted when the workspace completes. This way it works on both desktop and server


Reply


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