Save text file from Subfolders in loop

3 次查看(过去 30 天)
Hi, I'm using this rotine to identify my text files, and it's processing all my text files from my hundreds subfolders. But I don't know how I can save my text files in another place. Because I want to separate and save my text files from my subfolders in loop.
*
% Define a starting folder wherever you want
start_path = fullfile(matlabroot, 'C:\Users\Dani\Documents\PORTUGAL\Error_Sims');
% Ask user to confirm or change
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
% Get list of all subfolders
allSubFolders = genpath(topLevelFolder);
% Parse into a cell array
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
listOfFolderNames(:,1)=[];
numberOfFolders = length(listOfFolderNames);
% Process all text files in those folders.
for k = 1 : numberOfFolders
thisFolder = listOfFolderNames{k};
% fprintf('Processing folder %s\n', thisFolder);
% Get filenames of all TXT files.
filePattern = sprintf('%s/*error.txt*', thisFolder);
baseFileNames = dir(filePattern);
numberOfFiles = length(baseFileNames);
fullFileName=cell(numberOfFolders,1);
if numberOfFiles >= 1
for f = 1 : numberOfFiles
fullFileName{k,1} = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing text file %s\n', fullFileName{k,1});
end
% else
% fprintf('Folder %s has no text files in it.\n', thisFolder);
end
end*
Thank you!
  1 个评论
Geoff Hayes
Geoff Hayes 2018-4-17
Daniela - do you just want to copy or move the files from one location to another? Perhaps take a look at copyfile to see if that will do what you want.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by