您的位置:首页 > 其它

枚举指定路径下文件及文件夹复制到指定路径下

2009-10-01 14:17 399 查看
function DoCopyDir(sDirName, 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;
Form1.StatusBar1.Panels[0].Text := t;
Form1.StatusBar1.Refresh;
//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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: