comparison scripts/miscellaneous/fullfile.m @ 7288:1885f4c7e4b3

[project @ 2007-12-11 17:19:44 by jwe]
author jwe
date Tue, 11 Dec 2007 17:19:44 +0000
parents a1dbe9d80eee
children 4f6a73fd8df9
comparison
equal deleted inserted replaced
7287:3f29467c1667 7288:1885f4c7e4b3
23 ## @end deftypefn 23 ## @end deftypefn
24 24
25 function filename = fullfile (varargin) 25 function filename = fullfile (varargin)
26 26
27 if (nargin > 0) 27 if (nargin > 0)
28 filename = varargin{1}; 28 filename = "";
29 if (length (filename) < 1) 29 for first = 1:nargin
30 filename = "."; 30 tmp = varargin{first};
31 endif 31 if (! isempty (tmp))
32 if (strcmp (filename(end), filesep)) 32 filename = tmp;
33 filename(end) = ""; 33 break;
34 endif 34 endif
35 for i = 2:nargin 35 endfor
36 for i = first+1:nargin
36 tmp = varargin{i}; 37 tmp = varargin{i};
37 if (strcmp (tmp(1), filesep)) 38 if (! isempty (tmp))
38 tmp(1) = ""; 39 if (strcmp (tmp(1), filesep))
40 tmp(1) = "";
41 endif
42 if (i < nargin && strcmp (tmp(end), filesep))
43 tmp(end) = "";
44 endif
45 filename = strcat (filename, filesep, tmp);
39 endif 46 endif
40 if (i < nargin && strcmp (tmp(end), filesep))
41 tmp(end) = "";
42 endif
43 filename = strcat (filename, filesep, tmp);
44 endfor 47 endfor
45 else 48 else
46 print_usage (); 49 print_usage ();
47 endif 50 endif
48 51
49 endfunction 52 endfunction
53
54 %!assert (fullfile (""), "")
55 %!assert (fullfile (filesep ()), filesep ())
56 %!assert (fullfile ("", filesep ()), filesep ())
57 %!assert (fullfile (filesep (), ""), filesep ())
58 %!assert (fullfile ("", filesep ()), filesep ())
59 %!assert (fullfile ("foo"), "foo")
60 %!assert (fullfile ("", "foo"), "foo")
61 %!assert (fullfile ("foo", ""), "foo")
62 %!assert (fullfile ("", "foo", ""), "foo")
63 %!assert (fullfile ("foo", "bar"), strcat ("foo", filesep (), "bar"))
64 %!assert (fullfile ("foo", "", "bar"), strcat ("foo", filesep (), "bar"))
65 %!assert (fullfile ("foo", "", "bar", ""), strcat ("foo", filesep (), "bar"))
66 %!assert (fullfile ("", "foo", "", "bar", ""), strcat ("foo", filesep (), "bar"))