Code covered by the BSD License  

Highlights from
Function to find line in directory or folder

Function to find line in directory or folder

by

 

Parses directory from the first arg for the specified string in the 2nd arg for filetype in 3rd arg

find_word_code(input,search_text,extension)
function find_word_code(input,search_text,extension)
%this function search text files with extension and words 
%three parameters
%input - specify the director path
%search_text - text to search for in a file
%extension - specific file extension to search in 
%written - by Manit Shah
%Dated - 2013-04-16


f = dir(input);


for size = 1:length(f)
  
    if(~f(size).isdir)
      
      if(~isempty(strfind(f(size).name,extension)))
             filename = fullfile(input,f(size).name);      
        fid = fopen(filename,'r+');
       if(fid >= 0) 
        while ~feof(fid)
           
            line = fgetl(fid);
           if(~isempty(line))
               
            if(~isempty(strfind(line,search_text)))
               % temp =  fullfile(input, f(size).name);
               % strrep(line,search_text,replace_text);
                logbook_code(filename,line);
                continue;
            end
           end
           
          
        end
       else
         logbook_code(filename,'');  
       end
     fclose(fid);
      end
       
    else

       if(isempty(strmatch('.',f(size).name)))       
        sub = fullfile(input,f(size).name);
        find_word_code(sub,search_text,extension);
        
       end
    end
    
    
end
fclose all;

Contact us