source: trunk/src/private/ListDir.m @ 8

Last change on this file since 8 was 8, checked in by gostiaux, 14 years ago
File size: 4.5 KB
Line 
1%'ListDir': scan the structure of the directory tree (for dataview.m)
2%------------------------------------------------------------------------
3function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)
4
5ListRecords={};
6ListDevices={};
7ListXml={};
8irecord_tot=0;
9idevice_tot=0;
10ixml_tot=0;
11for iexp=1:length(ListExperiments)
12    List.Experiment{iexp}.name=ListExperiments{iexp};
13    hdir=dir(fullfile(CurrentPath,ListExperiments{iexp}));
14    idevice=0;
15    for isub=1:length(hdir)% scan the sub-directories  of the current experiment       
16        if hdir(isub).isdir
17            name=hdir(isub).name;%name of the current device
18            if ~isequal(name(1),'.')% subdirectory of the current experiment
19                [testnew,testselect]=test_select(name,ListDevices,ListDevices_in);
20                if testselect
21                    idevice=idevice+1;
22                    List.Experiment{iexp}.Device{idevice}.name=name;             
23                    if testnew
24                         idevice_tot=idevice_tot+1;
25                         ListDevices{idevice_tot}=name;
26                    end
27                    CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name);
28                    hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device
29                    if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record''
30                        hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device'   
31                        irecord=0;
32                        for isubsub=1:length(hsubdir)% subdirectories of the current device
33                            if hsubdir(isubsub).isdir                       
34                                RecordName=hsubdir(isubsub).name; 
35                                if ~isequal(RecordName(1),'.')
36                                    [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in);
37                                    if testselect
38                                        if testnew
39                                            irecord_tot=irecord_tot+1;
40                                            ListRecords{irecord_tot}=RecordName;
41                                        end
42                                        irecord=irecord+1;
43                                        List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName;
44                                        hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));%
45                                        for ixml=1:length(hsubsubxml)
46                                            XmlName=hsubsubxml(ixml).name;
47                                            List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName;
48                                            testnew=test_select(XmlName,ListXml,{});
49                                            if testnew
50                                                ixml_tot=ixml_tot+1;
51                                                ListXml{ixml_tot}=XmlName;
52                                            end
53                                        end
54                                    end             
55                                end
56                            end
57                        end
58                    else
59                        for ixml=1:length(hsubxml)
60                            XmlName=hsubxml(ixml).name;
61                            List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName;
62                            testnew=test_select(XmlName,ListXml,{});
63                            if testnew
64                                ixml_tot=ixml_tot+1;
65                                ListXml{ixml_tot}=XmlName;
66                            end
67                        end
68                    end
69                end
70            end
71        end
72    end
73end
74
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in)
77if ~isempty(ListDevices_in)
78    testnew=0;
79    testselect=0;
80    for ilist=1:length(ListDevices_in)
81        if isequal(name,ListDevices_in{ilist})
82            testnew=1;
83            testselect=1;
84            break
85        end
86    end
87else
88    testnew=1;
89    testselect=1;
90end
91if testnew
92    for ilist=1:length(ListDevices)
93         if isequal(name,ListDevices{ilist})
94              testnew=0;
95              break
96         end
97    end
98end
Note: See TracBrowser for help on using the repository browser.