Copying files using Matlab GUI - Matlab Code conversion (Unix to Windows)
5 次查看(过去 30 天)
显示 更早的评论
Hi, Could someone please modify the below code for copying files (written using UNIX commands) to make it work in Windows environment, satisfying the conditions given herewith.
Conditions:
Please copy each file with *.txt extension from different folders to the same folder (location specified by the user such as D:/testfinal/), with a click of the drop-down list box in GUI.. Once the files are copied to the destination folder, they need to be archived into a single *.zip archive file.
Files to be copied:
D:/test1/a1.txt
D:/test2/b2.txt
D:/test3/c3.txt
D:/test4/d4.txt
D:/test5/e5.txt
D:/test6/f6.txt
D:/test7/g7.txt
to the specified location D:/testfinal/ and archived as "copy_all_files_sub_folders.zip"
Code: clc
copy_all_se_dir_switch=1;
nasfilename_stk;
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;
elseif dum(j) == '/' ; dir_stem_length=j;
end end end
stk=[];stk1=[];
if exist('asm_stk','var') == 0;
errordlg(['Error! Write Nastran deck first']);
fclose('all');break
else; end
for i = 1:length(asm_stk);
dum=char(asm_include_stk(i,:));
dum2=[dum(1:dir_stem_length-1) char(op2_stk(i,:))]; dum2=cellstr(dum2);
dum3=dum(dir_stem_length-4:dir_stem_length-2);
stk=[stk;dum2];
stk1=[stk1;dum3];
end
op2_include_stk=stk;
asm_bnn_include_stk=stk1;
%------------------------------------------------------- %-- strip out the files - *.txt *.asm's and *.op2's for use later %------------------------------------------------------- stk=[];
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;
%------------------------------------------------------- % Now set up the file for NEdit shell execution %------------------------------------------------------- % copy_files_dir=uigetdir('/caedata/exchange/','Select Directory to copy files to');
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',[]);
% SE for i = 1:length(asm_stk);
fprintf(fid,'%s\n',['!mkdir ' asm_bnn_include_stk(i,:)]);
fprintf(fid,'%s\n',['!cp ' char(asm_include_stk(i,:)) ' 'asm_bnn_include_stk(i,:) '/' ]);
dum=char(asm_include_stk(i,:)); dum2=[dum(1:length(dum)-4) '.pch'];
fprintf(fid,'%s\n',['!cp ' dum2 ' ' asm_bnn_include_stk(i,:) '/' ]);
fprintf(fid,'%s\n',['!cp ' char(op2_include_stk(i,:)) ' 'asm_bnn_include_stk(i,:) '/' ]);
end
% *.txt fprintf(fid,' \n',[]);
for i = 1:length(dat_stk);
fprintf(fid,'%s\n',['!mkdir ' dat_bnn_include_stk(i,:)]);
fprintf(fid,'%s\n',['!cp ' 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',['!cp ' file_op_dir '/' master_nas_fname ' .']);
else fprintf(fid,'%s\n',['!cp ' long_filename ' .']);
end fprintf(fid,' \n',[]);
fprintf(fid,'%s\n',['!chmod -R 777 *']);
fprintf(fid,'%s\n',['!cd ..']);
fprintf(fid,'%s\n',['!chmod -R 777 *']);
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
!C:\Program Files\7-Zip\7zFM.exe
!7z a archive.zip .\copy_all_files_sub_folders.run\* end
When this code is executed in Matlab, it gives the error message:
Error: ??? Error using ==> win_open_mex
There is no application associated with the given file name extension. Error in ==> winopen at 54
win_open_mex(pathstr, filename);
Error in ==>
\matlab\v14\copy_all_se_dir.p>copy_all_se_dir at 94
??? Error while evaluating uimenu Callback
Please debug the code and provide me the solution at the earliest possible..
Thanks..!
4 个评论
Jan
2013-9-12
The question is not clear, your code still looks ugly, you still ask for providing a solution "at the earliest possible".
I do not expect, that this question get a useful answer.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!