为什么这个复制文件函数在复制硬盘上的文件没问题,而复制光盘的文件就出现了任何文件夹(包括其中的文件)都不会被复制? 仅仅复制文件。
------------
函数如下:(功能:把源目录下所有文件及子目录 复制到目标目录)
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;
var
F: TSearchRec;
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 {Copy Files under directories}
t:=sToDirName+'\'+tFile;
{show a message of copying}
{may be set a Golbal variant to VirDir}
Form_Installing.ToFile.Caption := '';
Form_Installing.ToFile.Repaint;
Form_Installing.ToFile.Caption:= t;
Form_Installing.ToFile.Repaint;
CopyFile(PChar(tfile),PChar(t),false);
Form_Installing.ProgressBar1.StepBy(1); {Show The ProgressBar status ;}
end;
until FindNextFile(F.FindHandle,FindFileData)=false;
FindClose(F);
end
else begin
ChDir(sCurDir);
result:=false;
exit;
end;
ChDir(sCurDir); {回到原来的目录下}
result:=true;
end;