Tips & Trix
If you are a user of one of the fine Addons available for NeoBook you might have noticed that they all have one thing in common. The Open dialogs always return a Full Path Statement to the target file. This is not a bad thing really. More often than not you would need the full path to exactly locate the selected file.
However, what if for some reason you need only the filename of the target file? Obviously you would need to strip away the path and be left with nothing but the actual filename.
I noticed that some Addons have a "feature" that strips strings in this manner. It seems to me that this would only add more code to the AddOn bloating it with functions that are already built into NeoBook anyway! (But what do I know?)
Anyway, when we look at any and all path statements on planet earth there is one thing that will ALWAYS be in EVERY path statement... Backslashes! (duh??) The backslash can be used as a marker to determine where the path ends and the filename begins. If you SearchStr "C:\Autoexec.bat" the backslash is the #3 position. Easy enough. But, what if you have a long path like...
"C:\Program Files\Company Name\Application Name\Filename.exe".
First of all, you have to scan that whole long string. Secondly you would have to pick out each backslash postion.
So, I tackled this backwards. Starting from the last character of the path statement scanning backwards. The very first backslash encountered (from right to left) is where the path ends. Viola! Use SubStr to extract a new variable starting from 1 to the marker position and you have your path. Use SubStr again from the marker position +1 to the StrLen of the path and you have your filename. (If you understood what I just said, congrats! You're as big a neo-geek as I am. ;) Read the remarks in the Working Example code below to follow the flow. It might make more sense!)
(replace addon.exe and parameters with your preffered addon filename)
. /////// Fire
up the AddOn and grab a file
. /////// Initiate
a VAR with the full PATH and the FILE
. for this
example let's assume this is the [pathfile]
. /////// BEGIN - Extract the filename from the path /////////////////////
the length of the string (59)
. set a var
at the end of the string (59)
. begin looking
at the full path from the last character (59)
if the character is a "\" backslash
. if the "\"
is found extract from one position more than the
. extract just
the path starting from the 1st character up to
. when everything
is done break out of the while loop with a zero
. here we are
moving backwards from character position 59
. /////// END - Extract the filename from the path /////////////////////
. a couple