# canonical_path

Definition: | string s = canonical_path(string path_in, integer is_directory=0, case_flags=CORRECT)
Description: | Return the full path and file name of the supplied file name.
pwa/p2js: | Not supported.
Comments: | In Phix this is just a simple wrapper for get_proper_path, which is defined in builtins\pgetpath.e (as is canonical_path). The two optional parameters are only present for compatibility with Euphoria, see technicalia for details, and in almost all cases should simply be omitted. Typically canonical_path() should only be required where you are going to compare/sort the resulting full paths. In theory a statement such as fn = open(canonical_path(path)) should work exactly the same and offer no benefits over the simpler fn = open(path).
See Also: | get_proper_path, upper, lower
Technicalia | The canonical_path(file,,CORRECT) form, which is equivalent to canonical_path(file,0,CORRECT), can simply be replaced (afaik) with canonical_path(file). The is_directory parameter is ignored. The Phix implementation determines whether path_in is a directory or file by looking on the disk and does not need to be told. The Phix version only accepts CORRECT (defined as 2 in psym.e) as a valid setting for case_flags. The Euphoria version allows other flags: AS_IS, TO_LOWER, and TO_SHORT, none of which are defined or supported by Phix. AS_IS makes little to no sense: if you are going to preserve the wrong case of src when something more accurate is on offer, my warped logic suggests you would want res = randomise_case(current_dir())&src to occur when src is not a full path... Likewise, TO_LOWER is semi-pointless: either res = lower(canonical_path(src)), or just res = lower(src), or the TO_LOWER+CORRECT form (in which existing parts of the path are given correct case and the rest lower) is just simply res = canonical_path(lower(src)). Finally, TO_SHORT is just something I actively want to avoid: while technically they may still exist 8,3 filenames should long be forgotten about by now. The latest Euphoria version appears to have extensive additions for Windows Vista (eg lower case drive letters, since rescinded), and other unix/case-insensitive filesystem/enhanced dir() features that I would stand no chance of adequately testing, plus the warning in the Euphoria documentation "Does not (yet) handle UNC paths or unix links" persuades me against investing any significant effort here, just yet. The Euphoria version replaces a leading tilde ('~') with $HOME on Unix platforms and %HOMEDRIVE%%HOMEPATH% in Windows. Phix does not (yet) support this and were such handling added, I should hope it would apply equally to open(), dir(), chdir(), etc.