changing file name in matlab

28 ビュー (過去 30 日間)
Jean Kim
Jean Kim 2019 年 9 月 15 日
コメント済み: okultekin 2019 年 9 月 15 日
I have files in one folder named '123445_MD.nii.gz','123454_MD.nii.gz', and so on. (all the # of digits are same; all 7 digits; xxxxxxx_MD.nii.gz)
I want to change the file name with '123445_FA.nii.gz' ... so on. Meaning want to change MD to FA only.
Thank you in advance.

回答 (2 件)

Guillaume
Guillaume 2019 年 9 月 15 日
Something like this should work:
folder = 'C:\somewhere\somefolder'; %whichever folder contains the files
filelist = dir(fullfile(folder, '*.gz'));
for fileidx = 1:numel(filelist)
movefile(fullfile(folder, filelist(idx).name), fullfile(folder, strrep(filelist(idx).name), '_MD', '_FA'));
end

okultekin
okultekin 2019 年 9 月 15 日
編集済み: okultekin 2019 年 9 月 15 日
FOR LINUX:
find the list of files and replace the words that u want.
Example:
find . -name '*gz' -exec bash -c ' mv $0 ${0/\MD/FA}' {} \;
if it doesnt work; please have a look out there->
https://unix.stackexchange.com/questions/175135/how-to-rename-multiple-files-by-replacing-string-in-file-name-this-string-conta
  2 件のコメント
Guillaume
Guillaume 2019 年 9 月 15 日
While indeed it may be a task more suited for the OS than matlab, note that this solution is linux only.
okultekin
okultekin 2019 年 9 月 15 日
Oh thanks, i edited!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by