Renaming multiple files in a folder
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (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
il 16 Gen 2023
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 Commento
Image Analyst
il 16 Gen 2023
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).
Categorie
Scopri di più su Communications Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!