02-01-2024 08:43 AM
I have a file path, which I convert to a string.
Example: C:\Test Path 1\Location 1\Location 2\This_Is_The_File_I_Want-1234.elf
I am trying to use the Match Regular Expression Function to search for the value of the file name between the last "\" and before ".elf". I am unsure how to configure it so that it will search between those two search parameters to return the file name.
Does anyone have a better method for searching for the name of that file? It can change over time, hence wanting to dynamically search for it.
Solved! Go to Solution.
02-01-2024 08:54 AM
First of all, don't convert it to a string:
02-01-2024 08:56 AM - edited 02-01-2024 08:59 AM
Sorry, Nevermind.
02-01-2024 09:46 AM - edited 02-01-2024 10:11 AM
In addition to what billko suggested, you can use the Get File Extension vi from the Advanced File Functions palette. This vi gives you the filename without extension as you require.
02-01-2024 11:39 AM - edited 02-01-2024 11:42 AM
@LearningLabVIEW wrote:
Does anyone have a better method for searching for the name of that file? It can change over time, hence wanting to dynamically search for it.
Yes, as mentioned.
As for the regular expression, there are tons of variations to get similar results.
Following is for educational purposes.
@LearningLabVIEW wrote:I am trying to use the Match Regular Expression Function to search for the value of the file name between the last "\" and before ".elf"
This returns anything* between the last "\" and before ".elf", but it does anchor .elf to the end of the string (the "$").
* Anything, including ".elf". So "C:\Test Path 1\Location 1\Location 2\This_Is_The_.e;lfFile_I_Want-1234.elf" returns "This_Is_The_.elfFile_I_Want-1234" as the first ".elf" isn't anchored to the end.
If you'd really want to match anything between the last \ and .elf the regex get a lot more complicated.
02-01-2024 12:13 PM - edited 02-02-2024 09:18 AM
Here's a combination of some of the suggestions:
And, as has been mentioned, if you already have it as "path" datatype, it never needs to be converted to a string in the first place. A full path is OS independent, but once you convert it to a string, it will be OS specific and the code will break on other platforms.
02-01-2024 12:33 PM
@pincpanter wrote:
In addition to what billko suggested, you can use the Get File Extension vi from the Advanced File Functions palette. This vi gives you the filename without extension as you require.
Oops, I forgot about that part of the requirement.