Skip to main content
Solved

How to delete (shape)files from a folder

  • January 21, 2025
  • 3 replies
  • 45 views

louielou1234
Contributor
Forum|alt.badge.img+5

Overwritting .shp files gives mixed results so my workaround is to delete the .shp file(s) first and then create the new version.  But I can not figure out how to do that --I read somewhere that writers have a ‘delete’ setting for the ‘fme_db_operation’ parameter but I can not locate that anywhere.  Can anybody tell me if FME has the ability to delete the .shp files in a folder?  Thanks!  Lewis

Best answer by bwn

Assuming Windows based system, with SystemCaller , use command line

Del “<shp_file_folder>\<shp_file_name>.* “

(with general use case assumption there will be no other unrelated files with a different extension by the same name)

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/del

You can retrieve and manipulate the list of files to target for deletion as 1 file per Feature with a File/Folder Reader, filter these with Eg. A Tester and pass each of the target shape files as input Features to SystemCaller to run the Del(ete) command line against.

 

The fme_db_operation attribute, typically output by a ChangeDetector, is not for file deletion.  As implied in the name, it is a database operation on rows/records within a database table being written to, being INSERT, UPDATE, DELETE or UPSERT for where the use case is to only write delta changes to the database table rather than an alternative writing mode that completely drops, deletes all rows or truncates the table and fully rewrite it.

 

 

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

3 replies

bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • January 22, 2025

Assuming Windows based system, with SystemCaller , use command line

Del “<shp_file_folder>\<shp_file_name>.* “

(with general use case assumption there will be no other unrelated files with a different extension by the same name)

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/del

You can retrieve and manipulate the list of files to target for deletion as 1 file per Feature with a File/Folder Reader, filter these with Eg. A Tester and pass each of the target shape files as input Features to SystemCaller to run the Del(ete) command line against.

 

The fme_db_operation attribute, typically output by a ChangeDetector, is not for file deletion.  As implied in the name, it is a database operation on rows/records within a database table being written to, being INSERT, UPDATE, DELETE or UPSERT for where the use case is to only write delta changes to the database table rather than an alternative writing mode that completely drops, deletes all rows or truncates the table and fully rewrite it.

 

 


becchr
Influencer
Forum|alt.badge.img+25
  • Influencer
  • January 22, 2025

I often use the filecopy writer to remove files

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

first create a temp folder with the tempPathnameCreator

https://docs.safe.com/fme/html/FME-Form-Documentation/FME-Transformers/Transformers/temppathnamecreator.htm

and move the files to that folder using the filecopier

 

Systemcaller works well too, but had troubles before getting this deployed to different environments. Using the temppathnamecreator + filecopier only uses FME


louielou1234
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • January 22, 2025

Thank you for these suggestions -- the System Caller instructions worked really well for me and I was able to delete one or multiple files from a folder. The FileCopy is also useful.  Thank you very much for you help! Lewis


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