matlab遍歷目錄下的文件並按文件名排序
clc;
clear;
rootDir='L:\GZY_20210305\2020-12-26-07-56-14_1\';
[ listFiles ] = listFiles202102( rootDir );
listFiles202102.m
function [ listFiles ] = listFiles202102( rootPath )
%UNTITLED12 此處顯示有關此函數的摘要
% 此處顯示詳細說明
listFiles={};
files = dir(rootPath);
files_name =sort_nat2021({files.name});
len=length(files);
for i=1:len
oldname=files_name{i};
newname=strcat(rootPath,num2str(i),'.txt');
listFiles=[listFiles,newname];
end
end
運行結果
L:\GZY_20210305\2020-12-26-07-56-14_1\1.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\2.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\3.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\4.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\5.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\6.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\7.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\8.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\9.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\10.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\11.txt
L:\GZY_20210305\2020-12-26-07-56-14_1\12.txt
listFiles202102