- 积分
- 16
- 注册时间
- 2009-3-4
- 仿真币
-
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2009-10-2 14:50:22
|
显示全部楼层
来自 重庆
有时候,我们要做一个 几万行代码的matlab 程序,每天,最好都有个备份。
因此,我做了个程序,用于备份。
这个程序,myBackUp(Pwd),就可以备份当前目录下的所有子目录内的程序代码,到指定的文件夹。
当然,也可以传递其它的路径,来备份。
- function myBackUp(curPwd)
- disp('Begin BackUP');
- try
- savefile = fullfile(pwd, 'Project_Work','SaveData','Config01.mat');
- tmpVar01=load(savefile, 'dName');
- backPath = tmpVar01.dName;
- disp('Current BackUp Directory is:');
- disp([' ' backPath]);
- disp('Do you want to Change BackUp Directory');
- reply = input('1.change\n【2】.no change\nChoose:\n', 's');
- catch
- reply='1';
- end
- if reply=='1'
- dName = 0;
- while dName== 0
- dName = uigetdir(pwd,'Select Data Path');
- end
- backPath = dName;
- if isempty(dir(fullfile(pwd, 'Project_Work','SaveData')))
- mkdir(fullfile(pwd, 'Project_Work','SaveData'));
- end
- try
- save(savefile,'dName','-append');
- catch
- save(savefile,'dName');
- end
- disp('BackUp Directory is :');
- disp(dName);
- disp('Change BackUp Directory OK!');
- end
- disp('------------------------');
- disp('Do you want to del .p files before BackUP:');
- reply = input('1.del\n【2】.no change\nChoose:\n', 's');
- if reply=='1'
- disp('------------------------');
- myPcode(2);
- end
- reply = input('Want some Prefix ? \n', 's');
- dest= datestr(now, 'yyyymmddTHHMMSS');
- if length(reply)>1
- dest=[reply '_' dest];
- end
- disp('------------------------');
- [status,message,messageid] =mkdir(backPath,dest);
- if status==1
- disp('Creat directory successful.');
- disp([message messageid]);
- else
- disp('Creat directory failed.');
- disp([message messageid]);
- return;
- end
- destdir=fullfile(backPath,dest);
- [status,message,messageid]=copyfile(curPwd,destdir);
- if status==1
- disp('Copy files successful.');
- disp([message messageid]);
- else
- disp('Copy files failed.');
- disp([message messageid]);
- return;
- end
- disp(['Source directory is: ' char(10) ' ' curPwd]);
- disp(['Destination directory is: ' char(10) ' ' destdir]);
- end
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|