Solved

How to ZIP folders in any path after successful translation?

  • 8 December 2017
  • 4 replies
  • 3 views

Badge +1

Hello everyone,

I´m still thinking about issue when after successful translation all folders in some path will be zipped. I have no idea, how to do this via simple workspace. Maybe only one possibility is to do that via Shutdown Python script. Unfortunately I´m not a huge expert in Python, could anybody help me please?

Thank You so much!

Lubo

icon

Best answer by david_r 8 December 2017, 15:30

View original

4 replies

Userlevel 5

I think the easiest solution is probably to replace your writers with FeatureWriters. Connect all the summary ports to a FeatureHolder + Sampler (1st feature only) and then use the ZipArchiver from the FME Hub.

If you're not too comfortable programming in Python, this will make life much easier for you, especially in the long run (maintenance).

Badge +1

I think the easiest solution is probably to replace your writers with FeatureWriters. Connect all the summary ports to a FeatureHolder + Sampler (1st feature only) and then use the ZipArchiver from the FME Hub.

If you're not too comfortable programming in Python, this will make life much easier for you, especially in the long run (maintenance).

Great tip! But what if You need to delete all directories which were zipped after zipping process? Is there any way how to remove them please?

 

 

Userlevel 5

To delete a directory tree recursively, you can use the following in a PythonCaller:

import shutil
import fmeobjects

def delete_directories(feature):
    directory_to_delete = feature.getAttribute('directory_to_delete')
    if directory_to_delete:
        shutil.rmtree(directory_to_delete)

You will have to provide a single feature with an attribute "directory_to_delete" containing the root of the folder structure to delete.

Example if you send a feature with the following attribute:

directory_to_delete = 'c:\output\temp123'

This will permanently delete ALL the files and subdirectories from c:\output\temp123 and down. Notice that the deleted files will NOT go to the recycle bin, they will be deleted for good. See also the documentation for rmtree.

NOTE: I assume no responsability whatsoever for the use or abuse of the above code! Be careful, you're on your own if something important gets deleted!

Badge +1

To delete a directory tree recursively, you can use the following in a PythonCaller:

import shutil
import fmeobjects

def delete_directories(feature):
    directory_to_delete = feature.getAttribute('directory_to_delete')
    if directory_to_delete:
        shutil.rmtree(directory_to_delete)

You will have to provide a single feature with an attribute "directory_to_delete" containing the root of the folder structure to delete.

Example if you send a feature with the following attribute:

directory_to_delete = 'c:\output\temp123'

This will permanently delete ALL the files and subdirectories from c:\output\temp123 and down. Notice that the deleted files will NOT go to the recycle bin, they will be deleted for good. See also the documentation for rmtree.

NOTE: I assume no responsability whatsoever for the use or abuse of the above code! Be careful, you're on your own if something important gets deleted!

Brillant! I have tested your code and it is completely what I have search!

 

 

Thank you @david_r once again!

 

Reply