MATLAB路径下文件遍历

Demo遍历输出路径下所有.csv文件的路径

clear all; close all; clc; foldPath = 'F:\yourfoldname'; searchFoldStr = strcat(foldPath,'\*.csv'); dirStruc = dir(searchFoldStr); dirCell = struct2cell(dirStruc); fileTotal = size(dirCell,1); for fileIndex = 1:fileTotal filepath = cell2mat(strcat(foldPath,dirCell(1,fileIndex))); % or filepath = strcat(foldpath,cell2mat(dirCell(1,fileIndex))); disp filepath; end

Another method
foldPath = 'F:\yourfoldname'; % fold path searchFoldStr = strcat(foldPath,'\*.csv'); dirStruc = dir(searchFoldStr); for fileIndex = 1:fileTotal filepath = strcat(foldPath,dirStruc(fileIndex).name); disp filepath; end

    推荐阅读