我在通过matlab复制子文件夹及其内容时遇到问题。我的文件夹包含许多级别的子文件夹。我想将包含文件的最后一个文件夹复制到其他路径。例如,A包含子文件夹B,并且文件夹B中包含文件夹C,文件夹C中包含文件夹D,文件夹D中存储文件1和文件2(我称文件夹D为最后一个文件夹)。我要复制文件夹D及其文件(文件1和文件2到其他文件夹)。您可以通过Matlab代码帮助我做到这一点吗?我正在使用窗户非常感谢
Folder A
|_sub folder B
|_sub folder C
|_sub folder D
|_file 1
|_file 2
%%%%%%%%%%%%%Function%%%%%%%%%%%%
function copysubfolder(source_A, destination)
end
码
function copysubfolder(source_A, destination)
OS = 'windows'; %// OP has mentioned Windows as his OS
paths = genpath(source_A);
if strcmp(OS,'windows')
%// On Windows GENPATH separates paths with semicolons
ind1 = strfind(paths(1:end-1),';');
else
%// On Linux at least, not sure about other OSs, GENPATH separates paths with colons
ind1 = strfind(paths(1:end-1),':');
end
copyfile(paths(ind1(end)+1:end-1),destination);
return;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句