Renaming multiple subfolders within folder

Hi all,
I have created a folder with 301 subfolders, each of the subfolders containing dicom images.
However I am required to rename each of the subfolders.
They are currently named P_6CMBCF_.......
And I would like to rename them as follows: P_Tomo_6CMBCF_.......
So I need to add _Tomo after the first letter.
How can I do this?
I am quite new to matlab so any help and guidance would be appreciated.
Thanks

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 26 日
編集済み: Ameer Hamza 2020 年 6 月 26 日

2 投票

Something like this
files = dir('P_6CMBCF_*');
for i=1:numel(files)
filename = files(i).name;
new_filename = [filename(1) '_Tomo' filename(2:end)];
movefile(filename, new_filename);
end

3 件のコメント

Riyad Khan
Riyad Khan 2020 年 6 月 26 日
編集済み: Riyad Khan 2020 年 6 月 26 日
Thanks, where do I add the main folder which contains all the images is it something like:
myfolder ='filename';
filePattern = fullfie(myfolder, 'P_6CMBCF_*');
theFiles = dir(FilePattern);
files = dir('P_6CMBCF_*');
for i=1:numel(files)
filename = files(i).name;
new_filename = [filename(1) '_Tomo' Tomo(2:end)];
movefile(filename, new_filename);
end
Ameer Hamza
Ameer Hamza 2020 年 6 月 27 日
Something like this
myfolder ='path_to_folder';
filePattern = fullfie(myfolder, 'P_6CMBCF_*');
theFiles = dir(FilePattern);
for i=1:numel(files)
filepath = fullfile(theFiles(i).folder, theFiles(i).name);
new_filepath = fullfile(theFiles(i).folder, [theFiles(i).name(1) '_Tomo' theFiles(i).name(2:end)]);
movefile(filepath, new_filepath);
end
Riyad Khan
Riyad Khan 2020 年 6 月 29 日
Thanks!

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

その他の回答 (1 件)

Gaurav Aggarwal
Gaurav Aggarwal 2020 年 6 月 26 日

1 投票

Hi Riyad,
You can refer the answer posted by Jan for renaming multiple folders, https://www.mathworks.com/matlabcentral/answers/16283-renaming-a-lot-of-folders-automatically-by-matlab
For folder names, you can replace "P_6CMBCF_" with "P_Tomo_6CMBCF_" using regex, something like the following,
newName = regexprep(AName{iFolder},"P_6CMBCF_","P_Tomo_6CMBCF_");
Hope this helps. Thanks.

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2020 年 6 月 26 日

コメント済み:

2020 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by