delphi拷贝整个目录(包括子目录)


本文整理自网络,侵删。

 
function CopyDirAll(sDirName:String;sToDirName:String):Boolean;
var
   hFindFile:Cardinal;      //拷贝整个目录(包括子目录)
   t,tfile:String; 
   sCurDir:String[255];
   FindFileData:WIN32_FIND_DATA; 
begin
   //先保存当前目录 
   sCurDir:=GetCurrentDir;
   ChDir(sDirName);
   hFindFile:=FindFirstFile('*.*',FindFileData);
   if hFindFile<>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
            CopyDirAll(sDirName+'\'+tfile,t)
         else
            CopyDirAll(sDirName+tfile,sToDirName+tfile);
      end
      else
      begin
           t:=sToDirName+'\'+tFile;
           CopyFile(PChar(tfile),PChar(t),True);
      end;
    until FindNextFile(hFindFile,FindFileData)=false;
    Windows.FindClose(hFindFile);
   end
   else
   begin
        ChDir(sCurDir);
        result:=false;
        exit;
   end;
   //回到原来的目录下
   ChDir(sCurDir);
   result:=true;
end;

相关阅读 >>

Delphi 获取内网所有ip地址

Delphi xe5调用外部扫描程序――谷歌 zxing

Delphi d10.x 并行库ppl编程之 tparallel.for

Delphi 使用泛型的 tarray 为动态数组排序

Delphi读写二进制文件

Delphi 字符串处理

Delphi setformfullscreen()窗体全屏显示

Delphi模拟点击网页中的按钮

Delphi 控制窗口显示隐藏

Delphi access技巧集

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...