Home > rest_20090422 > rest_RecursiveDir.m

rest_RecursiveDir

PURPOSE ^

Recursive do with Dir and all its sub-folders by Xiao-Wei Song

SYNOPSIS ^

function Result=rest_RecursiveDir(ADataDir, ACallback)

DESCRIPTION ^

Recursive do with Dir and all its sub-folders by Xiao-Wei Song
------------------------------------------------------------------------------------------------------------------------------
    Copyright(c) 2007~2010
    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
    Written by Xiao-Wei Song 
    http://resting-fmri.sourceforge.net
------------------------------------------------------------------------------------------------------------------------------

     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
    Version=1.0;
    Release=20071103;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

rest_RecursiveDir.m

SOURCE CODE ^

0001 function Result=rest_RecursiveDir(ADataDir, ACallback)
0002 %Recursive do with Dir and all its sub-folders by Xiao-Wei Song
0003 %------------------------------------------------------------------------------------------------------------------------------
0004 %    Copyright(c) 2007~2010
0005 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0006 %    Written by Xiao-Wei Song
0007 %    http://resting-fmri.sourceforge.net
0008 %------------------------------------------------------------------------------------------------------------------------------
0009 %
0010 %     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
0011 %    Version=1.0;
0012 %    Release=20071103;
0013     RunCallback(ADataDir, ACallback);
0014     pause(0.1);
0015     
0016     theFileList = dir(ADataDir);    
0017     ImgDirList ={};
0018     for x = 1:size(struct2cell(theFileList),2),
0019         if theFileList(x).isdir && (~ strcmpi(theFileList(x).name,'.')) && (~ strcmpi(theFileList(x).name,'..')),
0020             ImgDirList=[ImgDirList; {theFileList(x).name}];            
0021         end
0022     end    
0023     Result =ImgDirList;
0024     
0025     for x = 1:size(ImgDirList,1),
0026         RunCallback(fullfile(ADataDir,ImgDirList{x}), ACallback);        
0027         rest_RecursiveDir(fullfile(ADataDir,ImgDirList{x}), ACallback);
0028     end    
0029     
0030 function RunCallback(ADataDir, ACallback)    
0031     % Run the Callback
0032     if ~isempty(ACallback),
0033         if ischar(ACallback),
0034             if isempty(strfind(ACallback, '%s')),
0035                 eval(ACallback); %run callback for caller
0036             else
0037                 eval(sprintf(ACallback, ADataDir)); %run callback for caller
0038             end
0039         elseif isa(ACallback, 'function_handle')
0040             %I give 3 parameters, 20071103,
0041             %This method not work for reho_gui
0042             %Error:
0043             %      ??? Unable to find subsindex function for class
0044             %hObject, ADataDir, handles
0045             ACallback(gcbo, ADataDir, guidata(gcbo));
0046         end
0047     end

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005