Skip to main content

Hi,

I search for a simple way to do this:

- copy a file named "test.xlsx" as "test2.xlsx" in the same directory and

- copy the file "test2.xlsx" obtained as "test2 - 20180725.xlsx" in the same directory

with a simple script at the end of a workbench

thank you

Hi,

Have you tried FileCopy writer

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_ReadersWriters/filecopy/filecopy.htm

Pratap


Does it need to be a script?

You can use the file copy writer to copy and rename files at the end of your workspace


Does it need to be a script?

You can use the file copy writer to copy and rename files at the end of your workspace

I don't understand how to use this writer to do the job. At the end of my workbench i use a FeatureWriter to write my "test.xlsx" file in my directory and after this, how can i connect the filecopy writer after the featurewriter

 

 


I don't understand how to use this writer to do the job. At the end of my workbench i use a FeatureWriter to write my "test.xlsx" file in my directory and after this, how can i connect the filecopy writer after the featurewriter

 

 

Are you using a 2018 version of FME?

 

 


Hi,

Use another feature writer with FileCopy

Place necessary attributes with attribute creator in between

untitled.jpg


Are you using a 2018 version of FME?

 

 

No. I use a 2016 version

 

 


No. I use a 2016 version

 

 

A system caller after the featurewriter might be more straightforward in that case

 

 

e.g.

 

 

 


If you really want it in a script you could write something like this:

import os
import shutil
from datetime import date


today = date.today()
filename = FME_MacroValues['DestDataset_XLSXW']
path, fname = os.path.split(filename)
basename, extension = fname.split('.')
newfname = f'{basename} - {today.strftime("%y%m%d")}.{extension}'
newfilename = os.path.join(path,newfname)
shutil.copy(filename, newfilename)

its in python 3.6 btw.

for python 2.7 

newfname = '{} - {}.{}'.format(basename,today.strftime("%y%m%d"),extension)


A system caller after the featurewriter might be more straightforward in that case

 

 

e.g.

 

 

 

Hi,

 

The systemCaller give me that answer in the log :

 

 

SystemCaller: Executing `copy /Y C:\\Livraison AIXM 51 V2.0\\01 - Ecriture_mid_uuid/test.xlsx C:\\Livraison AIXM 51 V2.0\\01 - Ecriture_mid_uuid/tst2.xlsx'

 

2018-07-25 14:16:58| 17.1| 0.0|WARN |SystemCaller: Failed to Execute `copy /Y C:\\Livraison AIXM 51 V2.0\\01 - Ecriture_mid_uuid/test.xlsx C:\\Livraison AIXM 51 V2.0\\01 - Ecriture_mid_uuid/tst2.xlsx'

 

 

probably it doesn't succeed to write because it's a "/" and it needs a "\\" before "tst2.xlsx"

 


Please have a look to my picture to understand where is the issue:

 

 

ima1.png

 

 

I suceed by the "attributecreator" way to copy "test.xlsx" into "tst2.xlsx" using a private attribute "dir" which is obtained with a python script

 

 

ima2.png

 

 

and here is the log for this way

 

 

ima3.png

 

 

Why is it wrong with the systemcaller ???

 

 

This way allows to change the initial place of my global work. If i put the initial folder "Livraison AIXM 51 V2.0" containing all the subfolders in another folder (ie c:\\ or c:\\users\\desktop) it works

 

 

Why not with systemcaller ?

 


Try: copy "$(dir)\\test.xlsx" "$(dir)\\tst2.xlsx"