procedure TForm1.Button1Click(Sender: TObject);
var
sPath:string;
fsTemp:SHFILEOPSTRUCT;
i:integer;
begin
sPath:=InputBox('文件操作','输入复制路径','c:/windows');
if sPath<>''then begin
fsTemp.Wnd := Self.Handle;
//设置文件操作类型
fsTemp.wFunc :=FO_COPY;
//允许执行撤消操作
fsTemp.fFlags :=FOF_ALLOWUNDO;
for i:=0 to ListBox1.Items.Count-1 do begin
//源文件全路径名
fsTemp.pFrom := PChar(ListBox1.Items.Strings);
//要复制到的路径
fsTemp.pTo := PChar(sPath);
fsTemp.lpszProgressTitle:='拷贝文件';
if SHFileOperation(fsTemp)<>0 then
ShowMessage('文件复制失败');
end;
end;
end;
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
如:
CopyFile('c:/test.txt','d:/t.txt',true);是把c:/test.txt拷贝到d:/t.txt