Copy a file *.m into newly made folder (folder5, folder6, folder....)
Show older comments
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 Comments
Rik
on 23 Apr 2021
But you are already using sprintf. What don't you understand? Did you do a basic Matlab tutorial?
Yogesh Bhattarai
on 23 Apr 2021
Rik
on 23 Apr 2021
You show in your for loop that you know how to create a folder name. You use sprintf to create the folder name for mkdir. Why don't you do the exact same thing to create the path1 variable?
for n = 1:n
mkdir(sprintf('folder%d',n));
end
path1=sprintf('folder%d',n);
dos(['copy *.m ', path1])
Yogesh Bhattarai
on 23 Apr 2021
Yogesh Bhattarai
on 23 Apr 2021
Rather than very smelly copying of m-files into directories, most likely a much better approach is to use absolute/relative filenames when accessing data files.
Rik
on 23 Apr 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.
Yogesh Bhattarai
on 24 Apr 2021
Accepted Answer
More Answers (0)
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!