Copy a file *.m into newly made folder (folder5, folder6, folder....)
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yogesh Bhattarai
le 23 Avr 2021
Commenté : Yogesh Bhattarai
le 24 Avr 2021
for n = 1:n
mkdir(['folder',sprintf('%d',n)])
end
path1= 'folder(num2str(n))'; %%???? Here I got error for the path name
dos(['copy *.m ', path1])
8 commentaires
Rik
le 23 Avr 2021
Have you read the documentation for sprintf? It should be easy for you to add a second number if you did.
You should also take the advice from Stephen to hart.
Réponse acceptée
Image Analyst
le 23 Avr 2021
You should not do this:
for n = 1:n
It's very confusing (even though it works) because it appears that n is both the loop iterator and the ending iteration value and seems to take on two contradictory values. You should do this:
for k = 1 : n
To create a series of folders, do this:
n = 4; % Whatever...
pathList = cell(n, 1); % Preallocate a cell array to contain all the folder names.
for k = 1 : n
% Create the folder name as a character array.
folderName = fullfile(pwd, sprintf('Folder %2.2d', k));
if ~isfolder(folderName)
% Folder does not exist. Need to create it.
mkdir(folderName);
end
pathList{k} = folderName; % Save the folder name in a list.
end
path1= pathList{1}; % Or whatever you want...
path2= pathList{2}; % Or whatever you want...
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Debugging and Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!