cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Path and Filename from string

klandry
Deputy Chef II
Deputy Chef II

I need to extract and store the File Path and Filename.EXT from a string into 2 variables.
example:  \\Server\folder\folder\filename.ext

I want to end up with:
Variable1 = "\\Server\folder\folder\"
Variable2 = filename.ext

Is regex the best way to accomplish this, or is there another built-in method for parsing something like this?

1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

Try these:

[path data pill].split('\\').last

and

[path data pill].split("\\")[0..-2].join("\\")

The last one will return "\server\folder\folder", so you could just manually add the another "\" at the start and end.

View solution in original post

1 REPLY 1

gary1
Executive Chef III
Executive Chef III

Try these:

[path data pill].split('\\').last

and

[path data pill].split("\\")[0..-2].join("\\")

The last one will return "\server\folder\folder", so you could just manually add the another "\" at the start and end.