function I=RecursiveDir_OUH(DirPath,FileNameFilter,recursive)
  %This function return all files in a directory (DirPath) including all subdirectories.
  %Only file names which match logical expresion FileNameFiler will be
  %returned. Please see examples of logical expresions in the help menu
  %If FileNameFIler is not specified all filenames will be returned
  %It subfolders should not be included in the search the variable
  %recursive is se4t to false
  
  %Examples of call to funtion:
  %RecursiveDir('c:\home\cab','.dcm')  %Finds all files in c:\home\cab
  %which contain .dcm
  
  %RecursiveDir('c:\home\cab','.dcm$')  %Finds all files in c:\home\cab
  %which ends with .dcm
  
  %RecursiveDir('c:\home\cab',{'.dcm$','.img$'})  %Finds all files in c:\home\cab
  %which ends with either .dcm or .img
  
  %RecursiveDir('c:\home\cab','2249.*.tif$') %Find all files which contain
  %2249 followed by a number of charaters (.*) and end with .tif
  
  %RecursiveDir('c:\home\cab','\<3.*.tif$') %Find all files which starts
  %with the character 3 followed by a number of charaters and ends with
  %.tif
  
  %19-03-2015 CaB
  
  if nargin<1
    return;
  end
  if nargin==1
    FileNameFilter='.';
    recursive=true;
  end
  if nargin==2
    recursive=true;
  end
  %DirPath='C:\home\cab\4DConeBeam';
  files=dir(DirPath);
  %Remove the files . and .. 
  index=cellfun(@(x) ~strcmp(x,'.') && ~strcmp(x,'..'),{files.name});
  files=files(index);
  %Find files and directories
  index=[files.isdir];
  I={files(~index).name}';
  indexFilesOfInterest=cellfun(@(x) ~isempty(regexpi(x,FileNameFilter)),I);
  I=cellfun(@(x) fullfile(DirPath,x),I(indexFilesOfInterest),'UniformOutput',false);
  if recursive
    %Loop subdirectories
    temp=1:size(index,2);
    for i=temp(index)
      I=[I; RecursiveDir_OUH(fullfile(DirPath,files(i).name),FileNameFilter,recursive)];
    end
  end
end