# HG changeset patch # User Philip Nienhuis # Date 1690636884 -7200 # Node ID dc89f561451a1fa54bf04f6e1addd04dbdad828a # Parent 6f9f2e2c2ae870768e1f6eb6fd1d452489402929 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. diff -r 6f9f2e2c2ae8 -r dc89f561451a scripts/miscellaneous/fileparts.m --- 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 fileparts () %!error fileparts (1)