How can I import multiple .csv files that are in separate folders
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to import a large set of data and the problem I am running into is that they are stored in multiple folders inside a Main folder. I have changed my directory to this Main folder but it won't let me loop through the .csv files in the Main folder as they each are in their separate folder. Unfortunately, this is how the data is output by our data collection machines so is there a way I can potentially write a code that opens each folder and extracts the file information? I appreciate the help
Edit: I also do not have any sample code as this is the first step in my process
댓글 수: 0
답변 (2개)
Meade
2017년 3월 2일
Try this:
!!Careful, this will find ALL csvs in a folder!! You can further narrow down, e.g. by filename, using additional logical indices
mainFolder = uigetdir(); % Selectyour Main folder
[~,message,~] = fileattrib([mainFolder,'\*']);
fprintf('\n There are %i total files & folders.\n',numel(message));
allExts = cellfun(@(s) s(end-2:end), {message.Name},'uni',0); % Get exts
CSVidx = ismember(allExts,'csv'); % Search ext for "CSV" at the end
CSV_filepaths = {message(CSVidx).Name}; % Use CSVidx to list all paths.
fprintf('There are %i files with *.CSV exts.\n',numel(CSV_filepaths));
for ii = 1:numel(CSV_filepaths)
% Do import here
end
댓글 수: 0
Image Analyst
2017년 3월 2일
See attached demos, one for releases prior to R2016b and one for R2016b and later.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!