No BSD License  

Highlights from
M-File Alignment

image thumbnail
from M-File Alignment by Andre Strobel
Functions for cleaning m-code alignment

fAllSubDirectories(vPath)
% recursive function !!!
function [vAllSubDirectories] = fAllSubDirectories(vPath)

%fAllSubDirectories find all subdirectories in vPath
%
%  [vAllSubDirectories] = fAllSubDirectories(vPath)
%
%  Function for finding all subdirectories in vPath.
%
%  Example: [vAllSubDirectories] = fAllSubDirectories('C:\')
%
%  Author:     Dipl.-Ing. Andr Manfred Strobel
%  Copyright:  1999-2000 by DaimlerChrysler AG, FT1/AK
%  Matlab:     5.3, R11 (Win)
%  Date:       2000/01/06 11:00
%  Version:    001.00 * Released * / beta / alpha
%  Release:    01.00

if isequal(computer, ['PCWIN'])
	% computer system is Microsoft Windows
	cbWinSystem = -1; % system is windows
	cStandardSlash = ['\']; % define the standard slash
else
	% computer system is not Microsoft Windows
	cbWinSystem = 0; % system is not windows (probably unix type)
	% error(['Vecmo only works with Microsoft Windows'])
	% break; % break install procedure
	cStandardSlash = ['/']; % define the standard slash
end % of if

vAllSubDirectories = {}; % first there are no subdirectories

vDirectoryTOC = dir(vPath); % determine the table of contents of the given path/directory

for i=1:1:size(vDirectoryTOC, 1)
	% for all entries in the given directory do
	
	bValidDirectory = ~strcmp(vDirectoryTOC(i).name, ['.']); % the directory itself is not valid
	bValidDirectory = (bValidDirectory & (~strcmp(vDirectoryTOC(i).name, ['..']))); % the above directory is also not valid
	
	if ((vDirectoryTOC(i).isdir) & bValidDirectory)
		% the entry is a directory and this directory is valid
		
		if strcmp(vPath(size(vPath, 2)), cStandardSlash)
			% the desired path ends with a backslash -> fine
			vNewPath = [vPath, vDirectoryTOC(i).name]; % use the path with the i-th valid directory entry
		else
			% the desired path doesn't ends with a backslash
			vNewPath = [vPath, cStandardSlash, vDirectoryTOC(i).name]; % use the path with an additional backslash and the i-th valid directory entry
		end % of if
		
		% the list of all subdirectories is added the current entry and all its subdirectories (recursively!!!)
		vAllSubDirectories = [vAllSubDirectories; {vNewPath}; fAllSubDirectories(vNewPath)];
		
	end % of if
	
end % of for i

% end fAllSubDirectories

Contact us at files@mathworks.com