Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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 commentaires
Chandra Kurniawan
Chandra Kurniawan le 11 Jan 2012
Did you mean?
'info_001\data_001' 'info_002\data_002' 'info_003\data_003'
Chin
Chin le 11 Jan 2012
yes, so that the parent folder is 'info_*' while the sub folder is 'data_*'.

Connectez-vous pour commenter.

Réponse acceptée

Chandra Kurniawan
Chandra Kurniawan le 11 Jan 2012
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 commentaires
Chandra Kurniawan
Chandra Kurniawan le 11 Jan 2012
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by