Mercurial > octave
changeset 32230:dc89f561451a stable
fileparts.m: Allow for relative path on different drive on Windows (bug #64462).
* fileparts.m: Add stanza to check for relative path on a specific drive on
Windows. Add BISTs.
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Sat, 29 Jul 2023 15:21:24 +0200 |
parents | 6f9f2e2c2ae8 |
children | b609c7ecd59b |
files | scripts/miscellaneous/fileparts.m |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/fileparts.m Thu Aug 03 18:54:08 2023 +0200 +++ b/scripts/miscellaneous/fileparts.m Sat Jul 29 15:21:24 2023 +0200 @@ -53,7 +53,13 @@ endif if (ds == 0) - dir = ""; + if (ispc () && length (filename) >= 2 && strcmp (filename(2), ":")) + ## Relative path on Windows drive. At least, fix file name. + ds = 2; + dir = filename(1:2); + else + dir = ""; + endif elseif (ds == 1) dir = filename(1); else @@ -110,6 +116,14 @@ %! [d, n, e] = fileparts (".ext"); %! assert (strcmp (d, "") && strcmp (n, "") && strcmp (e, ".ext")); +%!testif ; ispc () <*64462> +%! [d, n, e] = fileparts ("c:file.ext"); +%! assert (strcmp (d, "c:") && strcmp (n, "file") && strcmp (e, ".ext")); + +%!testif ; ispc () <*64462> +%! [d, n, e] = fileparts ("c:d1/../d2/file.ext"); +%! assert (strcmp (d, "c:d1/../d2") && strcmp (n, "file") && strcmp (e, ".ext")); + ## Test input validation %!error <Invalid call> fileparts () %!error <FILENAME must be a single string> fileparts (1)