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. |
pwa/p2js: | Supported (after all it is only a bit of text extraction). |
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(). |
Auxillary function: |
string {path, name} = get_file_path_and_name(string filepath,
bool dropslash=true)
Convenience function that avoids having to invoke both get_file_path() and get_file_name(), with the same parameter. Note there is also a get_file_name_and_path() function which returns the same values the other way round, for when that seems more natural, besides having both means one less thing for the compiler to get all uppity and snooty about. |
Examples: |
?get_file_path("C:/Program Files (x86)/Phix/builtins/vm/papnd.e",0) ?get_file_path(`C:\Program Files (x86)\Phix\builtins\vm\papnd.e`,0) ?get_file_path("test.txt") ?get_file_path(`demo\test.txt`) ?get_file_path(`demo\rosetta`) ?get_file_path(`demo\rosetta\`) ?get_file_path(`demo\rosetta`,dropslash:=false) ?get_file_path(`demo\rosetta\`,dropslash:=false) -- output: -- `C:\Program Files (x86)\Phix\builtins\VM\` -- `C:\Program Files (x86)\Phix\builtins\VM\` -- `C:\Program Files (x86)\Phix` -- `C:\Program Files (x86)\Phix\demo` -- `C:\Program Files (x86)\Phix\demo` -- `C:\Program Files (x86)\Phix\demo\rosetta` -- `C:\Program Files (x86)\Phix\demo\` -- `C:\Program Files (x86)\Phix\demo\rosetta\` |
Implementation: | See builtins\file_utils.e (an autoinclude) for details of the actual implementation. |
See Also: | get_proper_path, get_proper_dir, get_file_name |
