How can i copy a full folder into another one?
53 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I am currently struggling with the following problem:
I created a new folder with
mkdir newDir;
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!
1 个评论
Jan
2021-10-30
编辑:Jan
2021-10-30
The question is not clear yet: What do you want to copy to where? copyfile(A,B) stores the contents of the folder A in the folder B. All subfolders are copied also. So what is the difference to the needed preserving of the folder structure?
The actual question, hwo to copy a full folder to another folder is solved by your code already:
copyfile(A, B)
回答(1 个)
Walter Roberson
2021-10-30
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');
fclose(fopen(outn, 'w'));
fclose(fopen(in1, 'w'));
fclose(fopen(in2, 'w'));
ls(tn1), ls(f1n), ls(f2n)
tn2 = tempname();
mkdir(tn2);
copyfile(tn1, tn2)
ls(tn2), ls(fullfile(tn2, 'f1')), ls(fullfile(tn2, 'f2'))
rmdir(tn1, 's'); rmdir(tn2, 's')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!