BOOL MakeSureDirectoryPathExists( IN LPSTR DirPath );
uses shellapiprocedure TForm1.Button1Click(Sender: TObject); var opstruc:tshfileopstruct; frombuf,tobuf:array[0..128] of char; begin fillchar(frombuf,sizeof(frombuf),0); fillchar(tobuf,sizeof(tobuf),0); //假设把d:\mpg目录下的所有文件拷贝到c:\abc目录下 strcopy(frombuf,'d:\mpg\*.*'); //mkdir('c:\abc');//创建目录c:\abc ,但会有因目录已存在而导致出错的可能,可随机创建(如根据系统时间) strcopy(tobuf,'c:\abc\'); with opstruc do begin wnd:=handle; wfunc:=fo_copy; pfrom:=@frombuf; pto:=@tobuf; fflags:=fof_noconfirmation or fof_renameoncollision; fanyoperationsaborted:=false; hnamemappings:=nil; lpszprogresstitle:=nil; end; shfileoperation(opstruc); messagedlg('拷贝完毕!',mtinformation,[mbok],0); end;
if not DirectoryExists('Data') then if not CreateDir('Data') then raise Exception.Create('创建目录异常');
);
var
opstruc:tshfileopstruct;
frombuf,tobuf:array[0..128] of char;
begin
fillchar(frombuf,sizeof(frombuf),0);
fillchar(tobuf,sizeof(tobuf),0);
//假设把d:\mpg目录下的所有文件拷贝到c:\abc目录下
strcopy(frombuf,'d:\mpg\*.*');
//mkdir('c:\abc');//创建目录c:\abc ,但会有因目录已存在而导致出错的可能,可随机创建(如根据系统时间)
strcopy(tobuf,'c:\abc\');
with opstruc do
begin
wnd:=handle;
wfunc:=fo_copy;
pfrom:=@frombuf;
pto:=@tobuf;
fflags:=fof_noconfirmation or fof_renameoncollision;
fanyoperationsaborted:=false;
hnamemappings:=nil;
lpszprogresstitle:=nil;
end;
shfileoperation(opstruc);
messagedlg('拷贝完毕!',mtinformation,[mbok],0);
end;
if not CreateDir('Data') then
raise Exception.Create('创建目录异常');