Pages: [1]
  Print  
Author Topic: [SOLVED] Macro + Path = Problem  (Read 170 times)
Q-Dog
Newbie
*
Posts: 32


« on: February 05, 2012, 07:43:58 PM »

Hi there,

I've got a problem modifying a path using "Generate Macro".

In the "File Loop" operator you get one (actually two) macro pointing the a folder (file_path and parent_path). If you want to modify this macro using "Generate Macro" you get a syntax error.

Example: suffix("%{parent_path}",10)

The problem is the backslash (\) in the path which will be interpreted wrong, but you can't escape it.. or can you?


Background:
I want to use the "File Loop" operator to read in a number of csv files in different subdirectories and store them in their respective folder.

Example:
"...\2012-05-02\file1.csv" ---> "...\myRepository\2012-05-02\file1.ioo"
"...\2009-10-31\file2.csv" ---> "...\myRepository\2009-10-31\file2.ioo"

Therefore I need the current directory (relative path), which I unfortunately isn't provided in "File Loop". Hence I tried to modify the macro "parent_path" (absolute path), which will lead to the error described above.


Cheers Q-Dog
« Last Edit: February 06, 2012, 07:25:00 PM by Q-Dog » Logged
awchisholm
Full Member
***
Posts: 157


« Reply #1 on: February 06, 2012, 01:40:37 AM »

Hello,

I had the same problem. In the end I wrote a Groovy script to manipulate the contents of the macro to return the parts I wanted.

Regards

Andrew
Logged
Q-Dog
Newbie
*
Posts: 32


« Reply #2 on: February 06, 2012, 10:44:19 AM »

Thanks for your answer awchisholm, could you maybe post that script?

// Edit
For everyone who's interested:

Code:
// Import the MacroHandler
import com.rapidminer.MacroHandler;

// Get the Macro Handler
MacroHandler handler = operator.getProcess().getMacroHandler();

// Get the Macro with the name "path"
String macro = handler.getMacro("path");

// Tokenize the macro by the delimiter \
List tokens = macro.tokenize("\\");

// Get the last token (the folder)
String folder = tokens.get(tokens.size()-1);

// Add a new macro named folder
handler.addMacro("folder",folder);
« Last Edit: February 06, 2012, 07:24:23 PM by Q-Dog » Logged
awchisholm
Full Member
***
Posts: 157


« Reply #3 on: February 09, 2012, 11:51:12 PM »

Hello

You beat me to it - I was about to post something similar

regards

Andrew
Logged
Pages: [1]
  Print  
 
Jump to: