Question

Copy files to new directory and add .txt file extension suffix

  • 15 April 2014
  • 3 replies
  • 13 views

Badge
Hi,

 

 

Using FME I want to copy a set of files in 1 directory to a different and then add a new file extension (whilst retaining the old).

 

 

I have created a workflow which works by reading all files within a directory, I then use the AttributeExposer, FilenamePartExtractor and StringConcatenator to obtain the details of existing filename and also create the new name. I then use a fanout on the text writer to output to the new directory. The problem is that I think it is inefficient as the contents of the files are being read in and then processed, when this only needs to be completed at file level and not contents level.

 

 

The input files are essentially text files from a mainframe, and named as user id and mainframe report output number, i.e.

 

 

asd0122.012

 

asd0122.013

 

asd0122.014

 

 

I am keen to retain the existing 'extension' as this provide information of report request order and therefore want to produce the following

 

 

asd0122.012.txt

 

asd0122.013.txt

 

asd0122.014.txt

 

 

I imagine that python script could be used to do this, could any one help? (Typically I know how to rename using ms dos, but do not know if I can 'call' or run an ms dos command within FME.)

 

 

 

The source and destination locations are known and will not change (or perhaps parameters could be used to add extra longevity to the process?).

 

 

(Source) e.g. C:\\project\\abc\\data\\input

 

(Destination) e.g. C:\\project\\abc\\data\\intermediate\\01\\01

 

 

 

Any help or advice would be appreciated,

 

 

 

I am using 2013sp1 build 13448

 

 

Regards,

 

 

Rob

3 replies

Badge +3
here is an old post from the former googlegoups

 

 

https://groups.google.com/forum/#!topic/fmetalk/HjRoYHf8Fug

 

 

 

> And attached is a TCL script that you'd run by

 

> saying:

 

>

 

>         fme renameall.tcl c:\\output\\92b034

 

>

 

> and it would do the renaming for you.  The

 

> renameall.tcl script is attached.

 

>

 

> Dale

 

>

 

>

 

> # Ensure we got all we needed on the command line

 

>

 

> if {$argc == 0} {

 

>     puts stderr "Syntax is: fme renameall.tcl

 

> sourceDirectory"

 

>     exit 1

 

> }

 

>

 

> # Get the source directory

 

>

 

> set sourceDir [lindex $argv 0]

 

>

 

> # Fix the slashes in it -- tcl only likes forward

 

> slashes

 

>

 

> regsub -all {\\\\} $sourceDir / sourceDir

 

>

 

> foreach i [glob $sourceDir/*] {

 

>   set lastSlashSpot [string last / $i]

 

>   file rename $i [string replace $i $lastSlashSpot

 

> $lastSlashSpot _]

 

> }

 

 

 

Gio
Userlevel 2
Badge +17
Hi Rob,

 

 

I think that

 

Directory and File Pathnames Reader [PATH],

 

StrindConcatenator,

 

AttributeRenamer,

 

and File Copy Writer [FILECOPY] can do that efficiently.

 

 

Takashi
Badge
Many thanks for the responses, I have successfully configured the workbench to rename copied version of the files as needed.

 

 

Takashi, I found the file_copy_dest_filename in the filecopy writer which was required following the filename extartion and string concatenation elements. This was part which had previously stumped me; I suspected that this feature must have existed.

 

 

Gio, thanks also for the referencing the Google post, this will also prove to be a useful technique.

 

 

Regards,

 

 

Rob

 

 

Reply