get_file_path

Definition: string path = get_file_path(string filepath, bool dropslash=true))
Description: Obtain the directory of a file.

filepath: the filepath from which to extract information.
dropslash: if false (0) the final path separator is retained.

Returns a string, the directory where the file is located.
Comments: Uses get_proper_path(), so on Windows if the directory exists the case of the result will match the actual directory, and as mentioned in get_proper_dir(), "demo\\rosetta" and "demo\\rosetta\\" yield different results - independently of dropslash, see the last four examples.

In other words, dropslash (for which the use of a named parameter is recommended) is primarily intended for/behaves more consistently when filepath identifies a file, rather than a directory, and indeed the main purpose of this whole routine is to split a path from a filename, rather than a path from a subdirectory.

Both forwardslash ('/') and backslash ('\\') are supported on all platforms, and converted appropriately in the output.

If a relative path is specified, the result is a fully qualified path, and if no path whatsoever is specified, the result (at least with dropslash left set to true) should match current_dir().
Examples:
?get_file_path("C:/Program Files (x86)/Phix/builtins/vm/papnd.e",0) -- displays "C:\\Program Files (x86)\\Phix\\builtins\\VM\\"
?get_file_path("test.txt")                                          -- displays "C:\\Program Files (x86)\\Phix"
?get_file_path("demo\\test.txt")                                    -- displays "C:\\Program Files (x86)\\Phix\\demo"
?get_file_path("demo\\rosetta")                                     -- displays "C:\\Program Files (x86)\\Phix\\demo"
?get_file_path("demo\\rosetta\\")                                   -- displays "C:\\Program Files (x86)\\Phix\\demo\rosetta"
?get_file_path("demo\\rosetta",dropslash:=false)                    -- displays "C:\\Program Files (x86)\\Phix\\demo\\"
?get_file_path("demo\\rosetta\\",dropslash:=false)                  -- displays "C:\\Program Files (x86)\\Phix\\demo\\rosetta\\"
See Also: get_proper_path, get_proper_dir, get_file_name