Definition: | string path = get_proper_dir(string filepath, bool remove_slash=false) |
Description: | Return the full directory path of the supplied file with the name removed. |
Comments: |
Result includes a trailing path separator, unless the optional parameter remove_slash is 1. Note that when a directory is specified the presence or otherwise of a separator at the end of the input string directly affects the output, as shown in the example below. Both forwardslash ('/') and backslash ('\\') are supported on all platforms, and converted appropriately in the output. Also as shown below, get_proper_dir(".") may sometimes be a slightly better alternative to current_dir(). The result should not be taken as confirmation of the actual existence of a directory. |
Examples: |
?get_proper_dir("p.exw") -- prints "C:\\Program Files (x86)\\Phix\\" ?get_proper_dir("demo") -- prints "C:\\Program Files (x86)\\Phix\\" ?get_proper_dir("demo\\") -- prints "C:\\Program Files (x86)\\Phix\\demo\\" ?get_proper_dir(".") -- prints "C:\\Program Files (x86)\\Phix\\" ?get_proper_dir(".",remove_slash:=true) -- prints "C:\\Program Files (x86)\\Phix" ?current_dir() -- prints "C:\\Program Files (x86)\\Phix" The use of a named parameter when setting remove_slash is recommended, to make the intent clear and the code easier to read. |
See Also: | get_proper_path, current_dir |