Skip to main content
Question

Use Attribute value as name for output folder


lambertus
Enthusiast
Forum|alt.badge.img+12

I extracted a zipped folder and searched within this folder for a PDF with an address. I would like to rename my unzipped folder with this address. At the moment I stored this address in an attribute.

 

Is there a way in FME I can rename the unzipped folder with this attribute value? Probably I need a Python Caller for that?

10 replies

nielsgerrits
VIP

An alternative way to do this is using a SystemCaller. With this transformer you can run dos commands.


Forum|alt.badge.img+2

If you are opening the PDF files to find the name you will probably have to us a shutdown script. The reason being you will have a sharing violation due to FME having the file open and the rename will fail. If the file isn't open, you can either a system caller or a shutdown script. They both work equally well.

 

Shutdown guide

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_QuickTranslator/Workbench/Startup_and_Shutdown_Python_Scripts.htm

 

 


lambertus
Enthusiast
Forum|alt.badge.img+12
  • Author
  • Enthusiast
  • October 9, 2020

Hi guys, thanks for your answers. I tried to create a new folder first which I could use to put my unzipped content in. Later on I could probably switch to rename my input folder. I used the following dos commands: However, no map was created in the Output folder.

SET a=D:\\Elbert\\Work\\Output\\

SET b=@Value(Name)

SET c="%a%%b%"

mkdir %c%

 

Outside FME using Command Window I used this commands (equivalent) which works perfect:

SET a=D:\\Elbert\\Work\\Output\\

SET b=Name

SET c="%a%%b%"

mkdir %c%

 

Probably I need to do something extra to my variable b in the System Caller which is the FME part of my path?


Forum|alt.badge.img+2
lambertus wrote:

Hi guys, thanks for your answers. I tried to create a new folder first which I could use to put my unzipped content in. Later on I could probably switch to rename my input folder. I used the following dos commands: However, no map was created in the Output folder.

SET a=D:\\Elbert\\Work\\Output\\

SET b=@Value(Name)

SET c="%a%%b%"

mkdir %c%

 

Outside FME using Command Window I used this commands (equivalent) which works perfect:

SET a=D:\\Elbert\\Work\\Output\\

SET b=Name

SET c="%a%%b%"

mkdir %c%

 

Probably I need to do something extra to my variable b in the System Caller which is the FME part of my path?

If the folder was created but no data was written, I would think you don't have the path specified in the writer in FME. You'll have to set that as a variable as well. It probably wrote somewhere but not to that folder.


lambertus
Enthusiast
Forum|alt.badge.img+12
  • Author
  • Enthusiast
  • October 9, 2020
jlbaker2779 wrote:

If the folder was created but no data was written, I would think you don't have the path specified in the writer in FME. You'll have to set that as a variable as well. It probably wrote somewhere but not to that folder.

I did not use a writer yet. I expected to be the output of the SystemCaller a new folder in my Windows Explorer? This is my workbench yet.SystemCaller


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • October 9, 2020

Why not construct the folder path in an AttributeCreator first

directory = D:\\Elbert\\Work\\Output\\@Value(foldername)

and then use a system caller

mkdir @Value(directory)

 

What is the exit code coming out of the system caller? It should be 0 if the system caller was successful


lambertus
Enthusiast
Forum|alt.badge.img+12
  • Author
  • Enthusiast
  • October 9, 2020
ebygomm wrote:

Why not construct the folder path in an AttributeCreator first

directory = D:\\Elbert\\Work\\Output\\@Value(foldername)

and then use a system caller

mkdir @Value(directory)

 

What is the exit code coming out of the system caller? It should be 0 if the system caller was successful

I get an error in Log Window about incorrect syntax. I used:

mkdir @Value(directory)

 

My exit code is 1.


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • October 9, 2020
lambertus wrote:

I get an error in Log Window about incorrect syntax. I used:

mkdir @Value(directory)

 

My exit code is 1.

If you use mkdir with a hardcoded value does it work?

What is the value you are trying to use? Are there any unusual characters present?


lambertus
Enthusiast
Forum|alt.badge.img+12
  • Author
  • Enthusiast
  • October 9, 2020
lambertus wrote:

I get an error in Log Window about incorrect syntax. I used:

mkdir @Value(directory)

 

My exit code is 1.

I tried this hardcoded one:

mkdir D:\\Elbert\\Work\\Output\\Test

=> exitcode 1

Output in Log Windows shows:

The syntax of the command is incorrect.

SystemCaller_2: Failed to Execute `mkdir D:\\Elbert\\Work\\Output/Test

 

Somehow the slash changed from \\ to / in the Log Message.

 

 


lambertus
Enthusiast
Forum|alt.badge.img+12
  • Author
  • Enthusiast
  • October 10, 2020

Hi guys, I found the solution :)

 

The trick was that the dos command need to be enclosed in quotation marks.

The final, working command was this one: "mkdir D:\\Elbert\\Work\\Output\\Test"

Beside that I found out that one needs to use extra quotation marks around your path in case the path contains spaces.


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