Skip to main content
Solved

copy external files based on result names


Forum|alt.badge.img

Hi,

I want to copy files based on workspace result values.

Example: a, b, c builders are applied for tenders of xyz road construction. All 3 companies tenders are integrated into one document and named as xyz road (its same as fme workspace result road names)

so when fme workspace result record contains xyz road, then pickup "xyz road" excel/pdf tender files and copy them into a specified folder path (or create new folder and copy files).

Any guidance on how to check the result road names with external files present in a directory (Lookup tables?)? is it possible in an easy way to automate it ? How can i compare result and copy respective files into a specified folder. Any guidance is helpful.

Thanks,

khk

Best answer by khk

Hi,
Done as below. I was thinking of creating variable for result features storage and 
reading pdf files to copy based on result names. But no need of variable creation with 
help of lookup table. Copy file is done with python caller.
import os
import fme
import fmeobjects
import shutil
def processFeature(feature):  
    # Create output directory with T_ID if the directory doesn't exist 
    dst = '//localhost/d$/Data/Output_Documents/PDF_Outputs/' + FME_MacroValues['T_ID'] + '/PDF/'
    fname =  feature.getAttribute('Route_Lookup')
    if not os.path.exists(dst):
        os.makedirs(dst)
    src='//localhost/d$/Data/Route/' + fname
    shutil.copyfile(src, dst + fname)
    pass
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        self.pyoutput(feature)
    def close(self):
        pass
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.

6 replies

stalknecht
Contributor
Forum|alt.badge.img+19
  • Contributor
  • January 31, 2016

The "Directory and File Pathnames"-Reader and the "PythonCaller"- or "SystemCaller"-Transformers could be helpfull. You can also use the Workspace Parameter "Shutdown Python Script" to do some afterwork.


Forum|alt.badge.img
  • Author
  • January 31, 2016

Hi stalknecht,

Thanks for throwing some light. I didn't find "Directory and File Pathnames"- Reader, in which category it is present.?


Forum|alt.badge.img+7
khk wrote:

Hi stalknecht,

Thanks for throwing some light. I didn't find "Directory and File Pathnames"- Reader, in which category it is present.?

It is not a transformer located in a category but a type of reader you can insert in your workspace.

I also would go with a PythonCaller, get the value of the attribute, create a URL for the files to copy and use the os.path.copy() method to copy the correct files.


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • February 1, 2016

I would go with the "File Copy"Writer. That writer will take arguments for source files and destination folder and filename. The attributes can be derived from attributes from a file (in your case the abc and xyz examples).


Forum|alt.badge.img+5
  • February 2, 2016

@khk

I personally think the file copy writer as erik_jan pointed out would be a lot simpler.

You could use an attribute creator with conditional value set to each 'xyzroad' to grab the external files for and then set that as the filecopy_source_dataset value. If you have multiple different values then you could concatenate the basename (assuming the roads share the same name as your external files) of the road dataset with the path name and .xls (or what ever your external files are) and then set that attribute as the filecopy_source_dataset.


Forum|alt.badge.img
  • Author
  • Best Answer
  • February 4, 2016
Hi,
Done as below. I was thinking of creating variable for result features storage and 
reading pdf files to copy based on result names. But no need of variable creation with 
help of lookup table. Copy file is done with python caller.
import os
import fme
import fmeobjects
import shutil
def processFeature(feature):  
    # Create output directory with T_ID if the directory doesn't exist 
    dst = '//localhost/d$/Data/Output_Documents/PDF_Outputs/' + FME_MacroValues['T_ID'] + '/PDF/'
    fname =  feature.getAttribute('Route_Lookup')
    if not os.path.exists(dst):
        os.makedirs(dst)
    src='//localhost/d$/Data/Route/' + fname
    shutil.copyfile(src, dst + fname)
    pass
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        self.pyoutput(feature)
    def close(self):
        pass

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