Z
zrj
Unregistered / Unconfirmed
GUEST, unregistred user!
如下程序中有backup和restore两个单选钮,speedbutton1(确定),button2(退出);
procedure Tbackup.SpeedButton1Click(Sender: TObject);
var path:string;
oldcursor:Tcursor;
FData:TShFileOpStruct;
begin
if Edit.text='' then
begin
showmessage('请输入要备份到的目录');
exit
end;
path:=ExtractFilePath(Application.Exename);
path:=path+'data';
oldcursor:=screen.Cursor;
if backup.Checked then
begin
if not DirectoryExists(edit.text) then
begin
if Application.messagebox('目录不存在,是不是要重新创建?','目录不存在',mb_okcancel+mb_iconquestion)=idok then
begin
mkdir(edit.text);
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(path);
fdata.pTo := PChar(edit.text);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end;
end
else
begin
if Application.messagebox('该目录下面的文件要被完全覆盖掉,要继续吗?','警告:',mb_okcancel+mb_iconquestion)=idok then
begin
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(path);
fdata.pTo := PChar(edit.text);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end;
end;
end;
if restore.Checked then
begin
if not DirectoryExists(edit.text) then
begin
messagedlg('你输入的目录不存在啊!',mtError,[mbYes],0);
exit
end
else
begin
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(edit.text);
fdata.pTo := PChar(path);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end
end;
end;
这断代码,有时候通过,有时候就提示不能copy文件,最常见是没有创建目录是,备份文件
可以,而目录存在是就提示出错,反正错得奇怪,我是copy来得代码,对整个目录copy不太
懂,请大家指点..
procedure Tbackup.SpeedButton1Click(Sender: TObject);
var path:string;
oldcursor:Tcursor;
FData:TShFileOpStruct;
begin
if Edit.text='' then
begin
showmessage('请输入要备份到的目录');
exit
end;
path:=ExtractFilePath(Application.Exename);
path:=path+'data';
oldcursor:=screen.Cursor;
if backup.Checked then
begin
if not DirectoryExists(edit.text) then
begin
if Application.messagebox('目录不存在,是不是要重新创建?','目录不存在',mb_okcancel+mb_iconquestion)=idok then
begin
mkdir(edit.text);
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(path);
fdata.pTo := PChar(edit.text);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end;
end
else
begin
if Application.messagebox('该目录下面的文件要被完全覆盖掉,要继续吗?','警告:',mb_okcancel+mb_iconquestion)=idok then
begin
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(path);
fdata.pTo := PChar(edit.text);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end;
end;
end;
if restore.Checked then
begin
if not DirectoryExists(edit.text) then
begin
messagedlg('你输入的目录不存在啊!',mtError,[mbYes],0);
exit
end
else
begin
screen.Cursor:=crhourglass;
Fdata.pFrom := PChar(edit.text);
fdata.pTo := PChar(path);
fdata.wFunc := FO_COPY
FData.Wnd := Application.Handle
fData.lpszProgressTitle := 'Wait';
fData.fFlags := FOF_ALLOWUNDO OR FOF_NOCONFIRMMKDIR
OR FOF_NOCONFIRMATION
OR FOF_SILENT
ShFileOperation( FData );
screen.Cursor:=oldcursor;
end
end;
end;
这断代码,有时候通过,有时候就提示不能copy文件,最常见是没有创建目录是,备份文件
可以,而目录存在是就提示出错,反正错得奇怪,我是copy来得代码,对整个目录copy不太
懂,请大家指点..