Question

TCL script for folder name

  • 18 November 2014
  • 7 replies
  • 16 views

Badge +1
Hi,

 

 

I would like to set the folder name of the source file to a published parameter, so I can use the folder name in the output directory filepath.

 

 

I have found in another post, the following TCL script for returning a filepath:

 

 

return [file dirname $FME_MacroValues(SourceDataset_SHAPE)]

 

 

Can someone please tell me how to amend this script so that it returns only the folder name not the whole directory? Or if the TCL option is not possible, any other ideas on using the folder name in the output file path?

 

 

(btw, I manage to extract the folder name within the workbench and set it to a published parameter, but the workbench still asks me for the published parameter when I run it, so it isn't working. I'm assuming this is because the output directory needs to be set at the start of the workbench so because I set the published parameter within the workbench it is too late).

 

 

Thanks,

7 replies

Userlevel 4
Badge +13
Hi,

 

 

Have a look at the directory and file pathnames reader, for source properties.

 

If you managed to extract the forlder name, why use it as a published parameter and not an attribute value?
Userlevel 2
Badge +17
Hi,

 

 

The "file" command with "split" option returns a list containing components of the path string. The folder name will be the second element from the last  if a file full path was set to the argument.

 

The direct answer to your question may be:

 

-----

 

return [lindex [file split $FME_MacroValues(SourceDataset_SHAPE)] end-1]

 

-----

 

 

Takashi
Badge +1
Hi Takashi,

 

 

I tried your script but I get the following error:

 

 

Starting translation...

 

 

INCLUDE -- failed to evaluate TCL expression `proc ParamFunc {} {

 

 upvar FME_MacroValues FME_MacroValues

 

return [lindex [file split $FME_MacroValues(SourceDataset_SHAPE)] end-1]

 

}

 

puts "MACRO OUT [ParamFunc]"

 

' -- can't read "FME_MacroValues(SourceDataset_SHAPE)": no such element in array

 

    while executing

 

file split $FME_MacroValues(SourceDataset_SHAPE)

 

    (procedure "ParamFunc" line 3)

 

    invoked from within

 

ParamFunc

 

    invoked from within

 

puts "MACRO OUT [ParamFunc]"

 

Program Terminating

 

 

Translation FAILED.

 

 

 

 
Badge +1
Itay, how do I use the attribute value to create a folder to send the output into? Can I set it somehow in "Fan out by Attribute"?
Badge +1
Ah I see I can Fan Out on the folder name attribute in the Navigator window!
Userlevel 2
Badge +17
Have you defined a user parameter named "SourceDataset_SHAPE" before the Tcl parameter definition?
Badge +3
you can fan out on writer under advanced (navigator window). For this you can use attributes created in the workspace.

 

 

This is very handy to create folders with subfolders with partitionised files based on one or more attributes of some feature/layer. For latter u can combine the DATAset fanout (in Navigator) with the feature-type fanout (in workspace)

Reply