Renaming multiple files in a folder
古いコメントを表示
I have files within a folder that have a common filename that I need to omit from all of the files.
For Example:
Antenna_REF_Angle00.s2p
Antenna_REF_Angle45.s2p
Antenna_REF_Angle90.s2p
I want to removed the word "REF" from all of the files in a single loop. Can someone help? Thanks
採用された回答
その他の回答 (2 件)
Folder = 'C:\Your\Folder';
FileList = dir(fullfile(Folder), 'Antenna_REF_*.s2p');
for k = 1:numel(FileList)
oldName = FileList(k).name;
newName = strrep(oldName, 'REF', '');
[status, msg] = movefile(fullfile(folder, oldName), fullfile(folder, newName));
assert(status == 1, msg);
end
MFK
2023 年 1 月 16 日
dinfo=dir('*.s2p');
for id = 1:length(dinfo)
% Get the file name
[~, f,~] = fileparts(dinfo(id).name);
newname = regexprep(f,'_REF_','');
movefile(dinfo(id).name,[newname '.s2p']);
end
1 件のコメント
Image Analyst
2023 年 1 月 16 日
To use this answer, since the code does not use fullfile(), you need to make sure that the current folder is the data folder. So the folder where the files are also must contain the above script (m-file).
カテゴリ
ヘルプ センター および File Exchange で Communications Toolbox についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!