summaryrefslogtreecommitdiff
path: root/modules/compatibility_functions/macros/mtlb_dir.sci
blob: 8d1cc80ae33cc49357c2eb877de71310f4059759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function [L]=mtlb_dir(path)
    // Emulation function for dir() Matlab function
    // See SCI/modules/fileio/macros/dir.sci for details

    // opt=='disp' -> result not affected to a variable
    // opt=='var' -> result affected to a variable

    rhs=argn(2)

    mask = int32(61440)
    dirtype = 16384
    basepath=""

    if rhs==1 then
        files=listfiles(path)
        basepath=path
    else
        files=listfiles()
    end

    n=size(files,"*")
    if n<>0 then
        files=gsort(files,"g","i")
    end

    lfiles=list()
    ldate=list()
    lbytes=list()
    lisdir=list()
    for k=1:n
        lfiles(k)=files(k)
        [x,ierr]=fileinfo(basepath+"/"+files(k))
        if ( (x == []) & (ierr== -1) ) then [x,ierr]=fileinfo(files(k)),end
        if x<>[] then
            w=getdate(x(6))
            month=[gettext("Jan"),..
            gettext("Feb"),..
            gettext("Mar"),..
            gettext("Apr"),..
            gettext("May"),..
            gettext("Jun"),..
            gettext("Jul"),..
            gettext("Aug"),..
            gettext("Sep"),..
            gettext("Oct"),..
            gettext("Nov"),..
            gettext("Dec")];

            ldate(k)=string(w(6))+"-"+month(w(2))+"-"+string(w(1))+" "+string(w(7))+":"+string(w(8))+":"+string(w(9))
            lbytes(k)=x(1);
            lisdir(k)=double(int32(x(2)) & mask) == dirtype
        end
    end
    if n==1 then
        lfiles=lfiles(1);
        ldate=ldate(1);
        lbytes=lbytes(1);
        lisdir=lisdir(1);
    end
    L=mlist(["st","dims","name","date","bytes","isdir"],int32([n 1]),lfiles,ldate,lbytes,lisdir)

endfunction