MATLAB修改一文件夹下所有txt文件名

%% 修改txt文件名
clear 
clc
close all

% 数据所在路径
datapath = 'E:\database\'; 
% 查看的数据列表
filelistName = 'filelist.txt';
filelist = strcat(datapath,filelistName);
fidfile = fopen(filelist,'r');
if fidfile < 0
    error('数据文件名打开错误!');
end
% 结果所在路径
respath1 = 'E:\AllRes\';

tline = fgetl(fidfile);
fileno = 0;
val = 0;
while ischar(tline)
    %%
    rname = strtrim(tline);
    if (1 == strncmp(rname,'#',1))
        tline = fgetl(fidfile);
        continue;
    end
    fileno = fileno + 1;
    % txt文件名字符串的组合函数 strcat
    oldname = strcat(respath1,'RefPlethPV_',rname,'.txt');
    newname = strcat(respath1,'RefREDPV_',rname,'.txt');
    % txt文件名修改函数 movefile
    movefile(oldname,newname);
    
    %% 读入下一条数据
    tline = fgetl(fidfile);
end

你可能感兴趣的:(MATLAB处理数据文本问题)