How to create a dynamic parent folder and than create another subfolder in the parent folder?

For example, parent folder is 'info_001, info_002, info_003' while sub folder is 'data_001, data_002, data_003'. How do I make it so that in the info_001 will contain data_001 sub folder and so on. So that I can get the result such as following
'data_001\data_001' 'data_002\data_002' 'data_003\data_003'
I have wrote a code but i cant get what i want.
name = dir('info_*');
a = numel(name);
for b = (a(1) + 1) : (a(1) + 3)
c = num2str(b, '%03i');
mkdir(sprintf(['info_%s', c], ['\data_%s', c]));
end
what I am missing?
Thanks for helping!

2 件のコメント

Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 11 日
Did you mean?
'info_001\data_001' 'info_002\data_002' 'info_003\data_003'
Chin
Chin 2012 年 1 月 11 日
yes, so that the parent folder is 'info_*' while the sub folder is 'data_*'.

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

 採用された回答

Hi,
If I did not misunderstand,
info_001 should contains data_001
info_002 should contains data_002
info_003 should contains data_003
name = dir('info_*');
foldername = 'data_00';
for num = 1 : length(name)
mkdir(name(num).name,strcat(foldername,num2str(num)));
end

6 件のコメント

Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 11 日
Have you created the parent folders??
Let say there is no parent folders.
My code below will create parent folders and its sub folders.
Please try.
parentfolder = 'info_00';
subfolder = 'data_00';
parentnum = 3;
subnum = 1;
for pn = 1 : parentnum
mkdir(pwd,strcat(parentfolder,num2str(pn)));
for sn = 1 : subnum
mkdir(strcat(parentfolder,num2str(pn)),strcat(subfolder,num2str(sn)));
end
end
Chin
Chin 2012 年 1 月 11 日
how do I create the folder that contains _001, _002 ... can be generated using something like this
num2str(b, '%03i')
because I would like the number for parent folder and sub folder can be generated by itself when the for loop number is increase until 100. So that the folder number can be like this
info_101\data_101, info_102\data\102 and so on.
Thanks a lot.
Chin
Chin 2012 年 1 月 11 日
i solved that problem. Thanks a lot.
parentfolder = 'info_';
subfolder = 'data_';
parentnum = 5;
subnum = 3;
for pn = 1 : parentnum
numI = num2str(pn, '%03i');
mkdir(pwd,strcat(parentfolder,num2str(numI)));
for sn = 1 : subnum
numK = num2str(sn, '%03i');
mkdir(strcat(parentfolder,num2str(numI)),strcat(subfolder,num2str(numK)));
end
end
Chin
Chin 2012 年 1 月 11 日
i solved that problem. Thanks a lot.
parentfolder = 'info_';
subfolder = 'data_';
parentnum = 5;
subnum = 3;
for pn = 1 : parentnum
numI = num2str(pn, '%03i');
mkdir(pwd,strcat(parentfolder,num2str(numI)));
for sn = 1 : subnum
numK = num2str(sn, '%03i');
mkdir(strcat(parentfolder,num2str(numI)),strcat(subfolder,num2str(numK)));
end
end
Chandra Kurniawan
Chandra Kurniawan 2012 年 1 月 11 日
Yes, I see
parentfolder = 'info_';
subfolder = 'data_';
parentnum = 10;
subnum = 1;
for pn = 1 : parentnum
bb = num2str(pn, '%03i');
mkdir(pwd,strcat(parentfolder,bb));
for sn = 1 : subnum
mkdir(strcat(parentfolder,bb),strcat(subfolder,bb));
end
end
Chin
Chin 2012 年 1 月 11 日
yes. really thanks a lot.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by