Home > . > ListDir.m

# ListDir

## PURPOSE

'ListDir': scan the structure of the directory tree (for dataview.m)

## SYNOPSIS

function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)

## DESCRIPTION

    'ListDir': scan the structure of the directory tree (for dataview.m)
    ------------------------------------------------------------------------

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- dataview TEST 'dataview': function for scanning directories in a campaign (TEST)
- editxml 'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)
- geometry_calib 'geometry_calib': performs geometric calibration from a set of reference points

## SUBFUNCTIONS

- function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in)

## SOURCE CODE

    0001 %'ListDir': scan the structure of the directory tree (for dataview.m)
    0002 %------------------------------------------------------------------------
    0003 function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)
    0004
    0005 ListRecords={};
    0006 ListDevices={};
    0007 ListXml={};
    0008 irecord_tot=0;
    0009 idevice_tot=0;
    0010 ixml_tot=0;
    0011 for iexp=1:length(ListExperiments)
    0012     List.Experiment{iexp}.name=ListExperiments{iexp};
    0013     hdir=dir(fullfile(CurrentPath,ListExperiments{iexp}));
    0014     idevice=0;
    0015     for isub=1:length(hdir)% scan the sub-directories  of the current experiment
    0016         if hdir(isub).isdir
    0017             name=hdir(isub).name;%name of the current device
    0018             if ~isequal(name(1),'.')% subdirectory of the current experiment
    0019                 [testnew,testselect]=test_select(name,ListDevices,ListDevices_in);
    0020                 if testselect
    0021                     idevice=idevice+1;
    0022                     List.Experiment{iexp}.Device{idevice}.name=name;
    0023                     if testnew
    0024                          idevice_tot=idevice_tot+1;
    0025                          ListDevices{idevice_tot}=name;
    0026                     end
    0027                     CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name);
    0028                     hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device
    0029                     if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record''
    0030                         hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device'
    0031                         irecord=0;
    0032                         for isubsub=1:length(hsubdir)% subdirectories of the current device
    0033                             if hsubdir(isubsub).isdir
    0034                                 RecordName=hsubdir(isubsub).name;
    0035                                 if ~isequal(RecordName(1),'.')
    0036                                     [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in);
    0037                                     if testselect
    0038                                         if testnew
    0039                                             irecord_tot=irecord_tot+1;
    0040                                             ListRecords{irecord_tot}=RecordName;
    0041                                         end
    0042                                         irecord=irecord+1;
    0043                                         List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName;
    0044                                         hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));%
    0045                                         for ixml=1:length(hsubsubxml)
    0046                                             XmlName=hsubsubxml(ixml).name;
    0047                                             List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName;
    0048                                             testnew=test_select(XmlName,ListXml,{});
    0049                                             if testnew
    0050                                                 ixml_tot=ixml_tot+1;
    0051                                                 ListXml{ixml_tot}=XmlName;
    0052                                             end
    0053                                         end
    0054                                     end
    0055                                 end
    0056                             end
    0057                         end
    0058                     else
    0059                         for ixml=1:length(hsubxml)
    0060                             XmlName=hsubxml(ixml).name;
    0061                             List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName;
    0062                             testnew=test_select(XmlName,ListXml,{});
    0063                             if testnew
    0064                                 ixml_tot=ixml_tot+1;
    0065                                 ListXml{ixml_tot}=XmlName;
    0066                             end
    0067                         end
    0068                     end
    0069                 end
    0070             end
    0071         end
    0072     end
    0073 end
    0074
    0075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0076 function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in)
    0077 if ~isempty(ListDevices_in)
    0078     testnew=0;
    0079     testselect=0;
    0080     for ilist=1:length(ListDevices_in)
    0081         if isequal(name,ListDevices_in{ilist})
    0082             testnew=1;
    0083             testselect=1;
    0084             break
    0085         end
    0086     end
    0087 else
    0088     testnew=1;
    0089     testselect=1;
    0090 end
    0091 if testnew
    0092     for ilist=1:length(ListDevices)
    0093          if isequal(name,ListDevices{ilist})
    0094               testnew=0;
    0095               break
    0096          end
    0097     end
    0098 end