How can i copy a full folder into another one?
12 views (last 30 days)
Hello everyone, I am currently struggling with the following problem:
I created a new folder with
Then I considered a single folder taken from
folder = uigetdir ('my_path'...
,'select the folder to analyze');
Now, what I want to do is to have folder into newDir, but writing
copyfile (folder ,'newDir');
I have all the elements of folder copied into newDir, while I need the full folder structure to be preseved, since I am gonna add more folders later and I want to keep them separate in newDir.
What should I do?
Thanks for your help!
Walter Roberson on 30 Oct 2021
Nope, copyfile works fine to preserve the folder structure.
tn1 = tempname();
f1n = fullfile(tn1, 'f1');
f2n = fullfile(tn1, 'f2');
mkdir(tn1); mkdir(f1n); mkdir(f2n);
outn = fullfile(tn1, 'only_in_outer.txt')
in1 = fullfile(f1n, 'only_in_f1.txt');
in2 = fullfile(f2n, 'only_in_f2.txt');
ls(tn1), ls(f1n), ls(f2n)
tn2 = tempname();
ls(tn2), ls(fullfile(tn2, 'f1')), ls(fullfile(tn2, 'f2'))
rmdir(tn1, 's'); rmdir(tn2, 's')