北京市住房和城乡建设部网站首页,html手机界面模板,婚恋网站排名前10,提高网站建设水平需求
有一个比较深层的文件夹#xff0c;每个文件夹及其子文件夹下都可能存在我所需要的csv文件#xff0c;写一个函数#xff0c;输入文件夹路径后可以返回所有符合要求的csv文件。
代码实现
% folder_path为输入的文件夹#xff0c;str为指定的文件所特有的关键字每个文件夹及其子文件夹下都可能存在我所需要的csv文件写一个函数输入文件夹路径后可以返回所有符合要求的csv文件。
代码实现
% folder_path为输入的文件夹str为指定的文件所特有的关键字例如csv
function [file_list]get_file_list_from_folder(folder_path,str)
%% find all the object file path in a folder
file_list{};
files dir(folder_path);
count1;
for i1:length(files)filefiles(i)if file.isdir ~contains(file.name,.) ~contains(file.name,..)subdirfullfile(folder_path,file.name);get_file_list_from_folder(subdir)elsepathfullfile(folder_path,file.name)if contains(path,str) % disp(path)file_list{count}path;countcount1;endend
endend说明,matlab中要实现python列表类似的可以储存字符串的矩阵可以通过cell去实现。cell的定义方式为var_cell{}。