# HG changeset patch # User Markus Mützel # Date 1649660966 -7200 # Mon Apr 11 09:09:26 2022 +0200 # Branch stable # Node ID 4a2c5676aff83de9207789edf6db76a874b3604a # Parent e219aacda1e55623dcbc0910e851dda41f98a396 Fix "ls" with glob patterns on Windows (bug #62282). * scripts/miscellaneous/ls.m: Exclude glob patterns from quoted part of string. diff -r e219aacda1e5 -r 4a2c5676aff8 scripts/miscellaneous/ls.m --- a/scripts/miscellaneous/ls.m Sun Apr 10 14:34:05 2022 -0700 +++ b/scripts/miscellaneous/ls.m Mon Apr 11 09:09:26 2022 +0200 @@ -32,9 +32,9 @@ ## ## List directory contents. ## -## The @code{ls} command is implemented by calling the native operating -## system's directory listing command---available @var{options} will vary from -## system to system. +## The @code{ls} function forwards to the @code{ls} command if it is available. +## It falls back to calling the native operating system's directory listing +## command. Available @var{options} may vary from system to system. ## ## Filenames are subject to shell expansion if they contain any wildcard ## characters @samp{*}, @samp{?}, @samp{[]}. To find a literal example of a @@ -64,28 +64,45 @@ error ("ls: all arguments must be character strings"); endif - if (nargin > 0) + ls_cmd = ls_command (); + + if (nargin > 0) args = tilde_expand (varargin); - if (ispc () && ! isunix ()) + + if (strncmp (ls_cmd, "ls", 2)) + if (ispc () && ! isunix ()) + ## Replace backslashes with forward slashes + args = regexprep (args, '\\(?![\*\[\]])', '/'); + ## Enclose paths, potentially having spaces, in double quotes: + idx = ! strncmp (args, '/', 1); + ## Enclose paths, potentially having spaces, in double quotes: + args(idx) = strcat ('"', args(idx), '"'); + ## Exclude glob patterns from quoted part of filenames string + args = regexprep (args, '(? 0 && strncmp (ls_cmd, "ls", 2)) args = ["-1 ", args]; endif