Hi,
I found some code online to return filenames from a directory and it's sub-directories. What would be useful for me would be if the path for each file name is ommitted e.g. insted of C:/My Documented/test.m I just get test.m in the results.
any help much apreciated.
function fileList = getAllFiles(dirName)
dirData = dir(dirName);
dirIndex = [dirData.isdir];
fileList = {dirData(~dirIndex).name}';
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),...
fileList,'UniformOutput',false);
end
subDirs = {dirData(dirIndex).name};
validIndex = ~ismember(subDirs,{'.','..'});
for iDir = find(validIndex)
nextDir = fullfile(dirName,subDirs{iDir});
fileList = [fileList; getAllFiles(nextDir)];
end
end