Continuing from part three where we looked at "2" and "3"...
4 - Unknown
I haven't found any indication of what functionality this might be, but it does behave differently to "1", which was also unknown. In this case it always returns a $status of 0 and $result is a blank string. I tried folders, subfolders, filenames and a blank string, with no difference in behaviour. I'm giving up, for now.
5 - Working directory
As discussed in part one, using numeric code "5" returns the working directory...
working = $result
The alternative is to use $ldir...
working = $ldir()
The alternative is more maintainable, safer and also performs better.
6 - Concatenate file path
This takes the file path which is currently in $result and then concatenates the path you pass in, automatically adding the folder delimiters where necessary. Here's some example code...
filepath = "C:\temp"
$result = filepath
filepath = $result
This will then populate $result with "C:\temp\test\". As you can see, I had excluded the delimiter from the end of both the original $result value and the value I passed it, but the interrupt command fixed that. Again, this is another string manipulation example, I came up with something like this...
filepath = "C:\temp"
if ( $scan(filepath,"/") < 1 ) ;calculate delimiter
del = "\"
del = "/"
pos = $length(filepath)
if ( filepath[pos] != del ) ;check filepath ends with delimiter
filepath = "%%filepath%%del%%%"
filepath = "%%filepath%%%test%%del%%%" ;concatenate filepath
As you can see, this isn't very concise, primarily because I'm accounting for Windows and Unix environments again, meaning that I have to first calculate the "del" local variable. You could of course use $concat instead of using substitution, like I have.
I tested these two methods over 2,000,000 iterations with the following results...
- interrupt = 00:06.67, 00:06.75, 00:06.72 (almost 7 seconds)
- alternative = 00:12.02, 00:12.00, 00:12.04 (about 12 seconds)
- without $scan = 00:09.04, 00:09.78, 00:09.74 (almost 10 seconds)
I added a third option which was the alternative but with a hardcoded delimiter instead of calculating it, so the performance can be improved by having a global register that holds this. Still, in this case the interrupt command is better for performance and is less lines of code.
Summary: Numeric code "4" remains unknown for now, "5" has been replaced by a better alternative and "6" seems to still be useful, although I think I'd still opt for string manipulation which I know that I can control over an undocumented feature.