A bit of regex help needed
Posted: 20 Jul 2011 13:20
Hi,
I want to use a function in my script, that does a fair amount of converting windows paths (with / without filenames) into unix paths.
The function gets an input (global variable) which can contain:
1.) one single windows path without a file name; e.g. <curpath>
2.) one single windows path with a file name; e.g. <curitem>
3.) a | separated list of windows paths with file names; e.g. get("SelectedItemsPathNames", "|");
It won't get a list with a | separated mix of paths with and without file names (when a user would select a file and a dir in the same directory).
Input examples:
Regardless of which of the 3 alternatives was the input I'd like to have one output:
I use two steps to convert the input in to unix style:
$CTU_SelectedItems contains input example 1, 2 or 3.
After that $UnixPathWithFileName contains:
Now I need a last regex to get only the path name (for any of the 3. cases).All path names will be the same, only the file names are different.
So:
Tia,
highend
I want to use a function in my script, that does a fair amount of converting windows paths (with / without filenames) into unix paths.
The function gets an input (global variable) which can contain:
1.) one single windows path without a file name; e.g. <curpath>
2.) one single windows path with a file name; e.g. <curitem>
3.) a | separated list of windows paths with file names; e.g. get("SelectedItemsPathNames", "|");
It won't get a list with a | separated mix of paths with and without file names (when a user would select a file and a dir in the same directory).
Input examples:
Code: Select all
1.) D:\Users\Highend\Tools\Steuer Erklärung
2.) D:\Users\Highend\Tools\Steuer Erklärung\Jahr 2010.pdf
3.) D:\Users\Highend\Tools\Steuer Erklärung\Jahr 2010.pdf|D:\Users\Highend\Tools\Steuer Erklärung\Jahr 2011.pdf
Code: Select all
1.) /Users/Highend/Tools/Steuer Erklärung
$CTU_SelectedItems contains input example 1, 2 or 3.
Code: Select all
$WindowsPath = $CTU_SelectedItems;
$UnixPath = regexreplace($WindowsPath, "([A-Za-z]):", "");
$UnixPath = replace($UnixPath, "\", "/");
Code: Select all
1.) /Users/Highend/Tools/Steuer Erklärung
or
2.) /Users/Highend/Tools/Steuer Erklärung/Jahr 2010.pdf
or
3.) /Users/Highend/Tools/Steuer Erklärung/Jahr 2010.pdf|/Users/Highend/Tools/Steuer Erklärung/Jahr 2011.pdf
So:
Code: Select all
$UnixPath = regexreplace($UnixPath, "???", "$1");highend