Rename files after a certain string in the file itself appears
3 ビュー (過去 30 日間)
古いコメントを表示
Dear MatLab users,
I have a bunch of files in a folder I need to rename. Basically, I want to delete the first 5 or 6 characters of the filename, those before a certain string. However, I do not know when this occurs, so I need to code it using something like strfind, but haven't managed to do it. Below is the code I have so far:
files_csv = dir('*.csv');
for i = 1 : length(files_csv)
baseFileName = files_csv(i).name;
%newFileName = baseFileName(6:end);
copyfile( baseFileName , newFileName )
end
Instead on newFileName = baseFileName(6:end), which only deletes the first 6 characters, I need to retain the characters after the string "PGA" appears.
Thanks
0 件のコメント
採用された回答
Jan
2022 年 4 月 27 日
An explicit example would be useful: old name and new name.
Maybe:
files_csv = dir('*.csv');
for i = 1 : length(files_csv)
baseFileName = files_csv(i).name;
newFileName = extractAfter(baseFileName, "PGA");
copyfile( baseFileName , newFileName )
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!