How to read all CSV files from specific folders?
177 views (last 30 days)
Show older comments
Hi, I want to open all CSV files and do a calculation on them. I used the code below and it worked
files = subdir('C:\Users\roozm\Desktop\New folder\*.csv');
Subdir function can do it easily. Now I want to be more specific and only open folder with the name of BIN and then read CSV files in only BIN folders.
How can I do that?
11 Comments
Paolo
on 1 Jun 2018
I'm not sure I understand what you mean by 'I do not know how to check if the file is in my current directory.'
Lets say your current working directory is :
C:\Users\roozm\
as from your OP. Could you list the full path of the .csv files you want, this way we can build the dir command?
Answers (3)
Walter Roberson
on 1 Jun 2018
files = dir('C:\Users\roozm\Desktop\New folder\**\BIN*\*.csv');
fullpaths = fullfile({files.folder}, {files.name});
Now fullpaths is a cell array of fully qualified .csv files that are directly under a BIN* folder anywhere under "New folder"
10 Comments
Roozbeh Yousefnejad
on 1 Jun 2018
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!