给你一个拷贝目录函数,有你需要的! function DoCopyDir(sDirName:String;sToDirName:String):Boolean; var F: TSearchRec; //hFindFile:Cardinal; t,tfile:String; sCurDir:String[255]; FindFileData:WIN32_FIND_DATA; begin //先保存当前目录 sCurDir:=GetCurrentDir; ChDir(sDirName); F.FindHandle:=FindFirstFile('*.*',FindFileData); if F.FindHandle<>INVALID_HANDLE_VALUE then begin if not DirectoryExists(sToDirName) then //如果目录不存在 ForceDirectories(sToDirName); //强迫建立目录 repeat tfile:=FindFileData.cFileName; if (tfile='.') or (tfile='..') then Continue; //跳过两个目录标识 if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then begin t:=sToDirName+'\'+tfile; if not DirectoryExists(t) then ForceDirectories(t); if sDirName[Length(sDirName)]<>'\' then DoCopyDir(sDirName+'\'+tfile,t) else DoCopyDir(sDirName+tfile,sToDirName+tfile); end else begin t:=sToDirName+'\'+tFile; FrmMain.msgWriter('正在拷贝: '+t); CopyFile(PChar(tfile),PChar(t),false); FrmMain.Prgb.StepBy(1); end; until FindNextFile(F.FindHandle,FindFileData)=false; FindClose(F); end else begin ChDir(sCurDir); result:=false; exit; end; //回到原来的目录下 ChDir(sCurDir); result:=true; end;
这是我以前提过的问题: procedure findall(disk,path: String; var fileresult: Tstrings); var fpath,s: String; fs: TsearchRec; begin fpath:=disk+path+'\*.*'; if FindFirst(fpath,faAnyFile,fs)=0 then begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then findall(disk,path+'\'+fs.Name,fileresult) else fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')'); while findnext(fs)=0 do begin if (fs.Name<>'.')and(fs.Name<>'..') then if (fs.Attr and faDirectory)=faDirectory then Findall(disk,path+'\'+fs.Name,fileresult) else begin fileresult.add(disk+path+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')'); end; end; end; Findclose(fs); end;
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;
var
F: TSearchRec;
//hFindFile:Cardinal;
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//先保存当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
F.FindHandle:=FindFirstFile('*.*',FindFileData);
if F.FindHandle<>INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then //如果目录不存在
ForceDirectories(sToDirName); //强迫建立目录
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue; //跳过两个目录标识
if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)]<>'\' then
DoCopyDir(sDirName+'\'+tfile,t)
else
DoCopyDir(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+'\'+tFile;
FrmMain.msgWriter('正在拷贝: '+t);
CopyFile(PChar(tfile),PChar(t),false);
FrmMain.Prgb.StepBy(1);
end;
until FindNextFile(F.FindHandle,FindFileData)=false;
FindClose(F);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到原来的目录下
ChDir(sCurDir);
result:=true;
end;
procedure findall(disk,path: String; var fileresult: Tstrings);
var
fpath,s: String;
fs: TsearchRec;
begin
fpath:=disk+path+'\*.*';
if FindFirst(fpath,faAnyFile,fs)=0 then
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
findall(disk,path+'\'+fs.Name,fileresult)
else
fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
while findnext(fs)=0 do
begin
if (fs.Name<>'.')and(fs.Name<>'..') then
if (fs.Attr and faDirectory)=faDirectory then
Findall(disk,path+'\'+fs.Name,fileresult)
else begin
fileresult.add(disk+path+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
end;
end;
end;
Findclose(fs);
end;