Skip to main content
Question

Use Attribute value as name for output folder

  • October 9, 2020
  • 10 replies
  • 140 views

lambertus
Enthusiast
Forum|alt.badge.img+23

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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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.

10 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • October 9, 2020

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


Forum|alt.badge.img+2
  • 194 replies
  • October 9, 2020

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+23
  • Author
  • Enthusiast
  • 141 replies
  • 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
  • 194 replies
  • 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?

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+23
  • Author
  • Enthusiast
  • 141 replies
  • October 9, 2020

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+44
  • Influencer
  • 3427 replies
  • 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+23
  • Author
  • Enthusiast
  • 141 replies
  • 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

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+44
  • Influencer
  • 3427 replies
  • October 9, 2020

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+23
  • Author
  • Enthusiast
  • 141 replies
  • October 9, 2020

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+23
  • Author
  • Enthusiast
  • 141 replies
  • 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.