Please find below, my Matlab code, for the above operation. The code doesn’t work as expected. It pops an error when compiled. Could someone please review the code and let me know where I am going wrong. Please help me..! Thank you..!!!
Important Variables used:
dat_stk - counter for no. of files to be copied i.e., 1 to 7
dat_bnn_include_stk - contains the immediate folder for the files i.e., b01, b02, b03, b04, b07, b09, b11
dat_include_stk - contains the path for all the files to be copied
Files:
'D:/abc/xyz/pqr/lmn/r1/sample/b01/a1.dat'
'D:/abc/xyz/pqr/aaa/r1/b02/b2.dat'
'D:/abc/xyz/pqr/aaa/r1/b03/c3.dat'
'D:/abc/xyz/pqr/aaa/r1/b04/d4.dat'
'D:/abc/xyz/pqr/aaa/r1/b07/e5.dat'
'D:/abc/xyz/pqr/aaa/r1/b09/f6.dat'
'D:/abc/xyz/pqr/aaa/r1/b11/g7.dat'
All these files need to be copied to the path D:/testfinal/ copy_all_files_sub_folders and archive the folder as "copy_all_files_sub_folders.zip"
Matlab Code:
clc
copy_all_se_dir_switch=1;
for i=1:length(dat_stk);
dum=char(dat_include_stk(i,:)); dum=['''' dum ''''];
for j = 1:(length(dum)-1);
if dum(j) == '\' ; dir_stem_length=j; % routine to work out dir stem lengths... PC
elseif dum(j) == '/' ; dir_stem_length=j; % routine to work out dir stem lengths... UNIX
end
end
end
stk=[];stk1=[];
if exist('asm_stk','var') == 0;
errordlg(['Error! Write Nastran deck first']);
fclose('all');break
else end
stk=[];
% stripping off the files to be copied *.txt
for i=1:length(dat_stk);
dum=char(dat_include_stk(i,:));
dum2=dum(dir_stem_length-4:dir_stem_length-2);
stk=[stk;dum2];
end
dat_bnn_include_stk=stk;
copy_files_dir=uigetdir('','Select Directory to copy files to');
fid=fopen('copy_all_files_sub_folders.run','w');
fprintf(fid,'%s\n',['!cd' copy_files_dir]);
fprintf(fid,' \n',[]);
fprintf(fid,' \n',[]);
for i = 1:length(dat_stk);
fprintf(fid,'%s\n',['mkdir ' dat_bnn_include_stk(i,:)]);
fprintf(fid,'%s\n',['copyfile ' char(dat_include_stk(i,:)) ' ' dat_bnn_include_stk(i,:) '/' ]);
end
fprintf(fid,' \n',[]);
dum=get(h404,'string');
if isempty(dum)==1
fprintf(fid,'%s\n',['copyfile ' file_op_dir '/' master_nas_fname ' .']);
else
fprintf(fid,'%s\n',['copyfile ' long_filename ' .']);
end
fprintf(fid,' \n',[]);
fprintf(fid,'%s\n',['cd ../']);
clear fid;
fclose('all');
copy_all_se_dir_switch=0;
if OS=='PCWI'
winopen ('copy_all_files_sub_folders.run')
else
!nedit copy_all_files_sub_folders.run
zip('copy_all_files_sub_folders.zip','copy_all_files_sub_folders');
end
---------------- Thank you..!!!