count the # of rows of CSV files in a folder
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
I have a bunch of CSV files in a folder. I understand that I can use
to count a number of rows of each file. Then how can one write a loop to read all csv files in a folder to calculate the sum of rows of CSV fiels in a folder? 
0 个评论
采纳的回答
  Voss
      
      
 2022-6-25
        your_folder = 'C:\path\to\folder';
files = dir(fullfile(your_folder,'*.csv'));
fullFileNames = fullfile(your_folder,{files.name});
numRowsTotal = 0;
for ii = 1:numel(files)
    datatable = readtable(fullFileNames{ii}, 'ReadVariableNames', false);  %or true if there is a header
    numRowsTotal = numRowsTotal + height(datatable);
end
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

