comparison scripts/miscellaneous/ls.m @ 18240:3d22b24863b9

ls.m: Enclose paths with spaces in double quotes on Windows (bug #40989). * ls.m: Only enclose paths in double quotes on Windows systems. Remove now redundant check for '/' at end of filename. For UNIX systems, pass special characters '[]' through to shell.
author Rik <rik@octave.org>
date Tue, 07 Jan 2014 15:15:47 -0800
parents 0490de623fa0
children 12d1297d3a38
comparison
equal deleted inserted replaced
18239:c0f036b5e292 18240:3d22b24863b9
58 error ("ls: all arguments must be character strings"); 58 error ("ls: all arguments must be character strings");
59 endif 59 endif
60 60
61 if (nargin > 0) 61 if (nargin > 0)
62 args = tilde_expand (varargin); 62 args = tilde_expand (varargin);
63 is_dos = (ispc () && ! isunix ()); 63 if (ispc () && ! isunix ())
64 if (is_dos) 64 idx = ! strncmp (args, '/', 1);
65 optsep = "/"; 65 ## Enclose paths, potentially having spaces, in double quotes:
66 args(idx) = strcat ('"', args(idx), '"');
67 ## shell (cmd.exe) on MinGW uses '^' as escape character
68 args = regexprep (args, '([^\w.*?])', '^$1');
66 else 69 else
67 optsep = "-"; 70 ## Escape any special characters in filename
68 endif 71 args = regexprep (args, '([^\w.*?-[]])', '\\$1');
69 idx = ! strncmp (args, optsep, 1);
70 ## Enclose paths, potentially having spaces, in double quotes:
71 args(idx) = strcat ('"', args(idx), '"');
72 if (is_dos)
73 ## shell (cmd.exe) on MinGW uses '^' as escape character
74 args = regexprep (args, '([^\w.*? -])', '^$1');
75 ## Strip UNIX directory character which looks like an option to dir cmd.
76 if (args{end}(end) == '/')
77 args{end}(end) = "";
78 endif
79 else
80 args = regexprep (args, '([^\w.*? -])', '\\$1');
81 endif 72 endif
82 args = sprintf ("%s ", args{:}); 73 args = sprintf ("%s ", args{:});
83 else 74 else
84 args = ""; 75 args = "";
85 endif 76 endif