Skip to main content
Solved

Add existing file to output ZIP

  • February 27, 2015
  • 3 replies
  • 26 views

Hello,

 

I have a workbench which converts Oracle spatial data to shapefile. I am creating a zip file in output folder. Now, I would like to add a metadata file which is in same folder where output zip is created. Is it possible to add/move existing file from folder to output zip.

 

 

Cheers

 

John

Best answer by takashi

Hi John,

 

 

I would use Python again.

 

-----

 

# Shutdown Python Script Example

 

import os, zipfile

 

 

if FME_Status == 1:

 

    zipPath = FME_MacroValues['DestDataset_SHAPE']

 

    metaPath = <existing metadata file path>

 

    if zipfile.is_zipfile(zipPath) and os.path.exists(metaPath):

 

        # Add the metadata file to the zip archive.

 

        zip = zipfile.ZipFile(zipPath, 'a')

 

        zip.write(metaPath, os.path.split(metaPath)[1])

 

        zip.close()

 

        

 

        # If you need to remove the original metadata file:

 

        os.remove(metaPath)

 

-----

 

 

Takashi
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

takashi
Influencer
  • Best Answer
  • February 27, 2015
Hi John,

 

 

I would use Python again.

 

-----

 

# Shutdown Python Script Example

 

import os, zipfile

 

 

if FME_Status == 1:

 

    zipPath = FME_MacroValues['DestDataset_SHAPE']

 

    metaPath = <existing metadata file path>

 

    if zipfile.is_zipfile(zipPath) and os.path.exists(metaPath):

 

        # Add the metadata file to the zip archive.

 

        zip = zipfile.ZipFile(zipPath, 'a')

 

        zip.write(metaPath, os.path.split(metaPath)[1])

 

        zip.close()

 

        

 

        # If you need to remove the original metadata file:

 

        os.remove(metaPath)

 

-----

 

 

Takashi

  • Author
  • February 27, 2015
Thanks Takshi. Worked like charm :)

fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • February 28, 2015
Hi,

 

A different approach using FME transformers is described here:

 

http://fmepedia.safe.com/articles/How_To/Including-Additional-Supporting-Files-in-your-Output-ZIP-File-Desktop-Zipster

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