필터 지우기
필터 지우기

Save text file from Subfolders in loop

조회 수: 3 (최근 30일)
Daniela Correa
Daniela Correa 2018년 4월 16일
댓글: Geoff Hayes 2018년 4월 17일
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