bug 3598
[scilab.git] / scilab / modules / fileio / macros / dir.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function L=dir(str)
11         
12         mask     = int32(61440);
13         dirtype  = 16384;
14         
15         if argn(2)==1 then
16         
17     if type(str) <> 10 then 
18       error(999,msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),'dir',1));
19     end 
20
21                 files    = listfiles(str);
22                 basepath = str;
23         else
24                 files    = listfiles();
25                 basepath = "";
26         end
27         
28         n = size(files,"*");
29         
30         if n==0 then
31         
32                 files = [];
33                 dt    = [];
34                 bytes = [];
35                 isd   = [];
36                 
37         else
38                 
39                 files    = gsort(files,"lr","i");
40                 dt       = zeros(n,1);
41                 bytes    = zeros(n,1);
42                 isd(n,1) = %f;
43                 
44                 for k=1:n
45                         if (basepath == '') then
46                                 [x,ierr] = fileinfo(files(k));
47                         else
48                                 [x,ierr] = fileinfo(basepath+"/"+files(k));
49                         end
50                 
51                         if ( (x == []) & (ierr== -1) ) then
52                                 [x,ierr] = fileinfo(files(k));
53                         end
54                         
55                         if x<>[] then
56                                 dt(k)    = x(6);
57                                 bytes(k) = x(1);
58                                 isd(k)   = (double(int32(x(2)) & mask) == dirtype);
59                         end
60                 
61                 end
62                 
63         end
64         
65         L = tlist(['dir','name','date','bytes','isdir'],files,dt,bytes,isd);
66         
67 endfunction