Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Difficulties with RegEx

Jesse89
7 - Meteor

Hi all,

 

I'd like to parse out some folder names and use them to organize my data.  I'm currently using a directory tool that outputs the filename and uses batch macros to combine multiple files together.  The macro works, now I'm just trying to grab the folder that each file came from as an additional data field.

 

Currently the File name looks like this:  \\SharedDrive\Organization\Folder Name 1\Folder Name 2\Survey.xlsx|||'Survey 2015$'

 

I know this can be done with multiple text to column tools using "\" as a delimiter, however, this task I do relatively frequently and would like to know how I can use RegEx to parse out that folder name.  I have previously used [-](.*) regex to treat "-" as my delimiter, but I am unsure on how to use special characters like "\".

 

Any help is greatly appreciated!

 

Thank you,

Jesse

6 REPLIES 6
Claje
14 - Magnetar

Unfortunately I don't have time at this second to offer you a RegEx solution - I'm sure someone else can offer one.


Here's a solution to get the folder name using one formula:

Replace([FILENAME],RIGHT([FILENAME],FINDSTRING(REVERSESTRING([FILENAME]),'\')),'')

Replace the [FILENAME] references with the field you are using.

This will essentially look for anything right of the last "\" character (the name of the file itself), and then replace that with nothing, leaving you with the folder path only.

MarqueeCrew
20 - Arcturus
20 - Arcturus

@Jesse89,

 

Have you tried 

FileGetDir([Path])

 

Here is some more "stuff" from help ...

 

FileAddPaths(Path1, Path2)

Adds two file path parts, making sure there is exactly one \ (backslash) between the two paths.

FileExists(Path)

Returns true if the file exists, false if it does not.

FileGetDir(Path)

Returns the directory portion of the path.

FileGetExt(Path)

Returns the extension of the path, including the . (period).

FileGetFileName(Path)

Returns the name portion of the path, without the extension.

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Claje
14 - Magnetar

Wow, I can't believe I literally never looked at these functions before.  That's a much more elegant solution.

Jesse89
7 - Meteor

Thanks Mark,

 

I was able to use FileGetDir([Path]) to narrow it down.  For the example used, this would give me "\\SharedDrive\Organization\Folder1\".

 

I then used two additional steps:  

 

Step 1: ReplaceFirst ([Path], "\\SharedDrive\Organization\", ""),

Output:  "\Folder1\".

Step 2: Trim([Path], "\")

Output: "Folder 1".  

 

It would be helpful if anyone had a RegEx solution, since the organization name could change in the future, which would render my solution ineffective.

 

Thank you!

Jesse

MarqueeCrew
20 - Arcturus
20 - Arcturus
Try this:

Regex_replace(Path,".*\\(.*)\\$", '$1')

It might work.

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Jesse89
7 - Meteor

Mark,

 

This led me down the right path. 

 

I was able to configure the RegEx Tool to parse the "FileName" field with the following Regular Expression:  .+\\(.*)\\

 

This let me output a new field that had only contained the folder name.

 

Thank you again!

Jesse

Labels