% tidy up
clear all; 
close all;

% get directory listing
list = dir;

% loop through list, entering each folder
for i = 1:length(list)
    
    % check if folder
    if list(i).isdir == 1 && ~strcmpi(list(i).name, '.') && ~strcmpi(list(i).name, '..')

        % enter folder
        cd(list(i).name);
        
        % get directory listing
        files = dir;
        
        % run fieldmapcomp for each text file
        for j=1:length(files)
            
            % check if .txt file
            if ~isempty(strfind(files(j).name, '.txt'))
                
                % create folder for results
                foldername = strrep(files(j).name, '.txt', '');
                mkdir(foldername);
                cd(foldername);
                
                % run fieldmapcomp
                fieldmapcomp('..\..\field-alan.txt', ['..\' files(j).name]);
                
                % return to current folder
                cd('..');
                
            end
            
        end
                
        % return to parent directory
        cd('..');
        
    end
    
end
