一段copy文件代码
写if FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY
找到目录也不认
写成if FindFileData.dwFileAttributes =2064就能判断是目录文件
还有就是加FindClose(hFindfile); 这句后编译不过以上两个问题为什么请帮我看看。
function TMainForm.DoCopyDir(sDirName, 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
begin
ForceDirectories(sToDirName);
end;
Memo1.Lines.Add('hFindFile <> INVALID_HANDLE_VALUE');
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
begin
Continue;
end;
//是目录文件的建立
if FindFileData.dwFileAttributes = 2064 //FILE_ATTRIBUTE_DIRECTORY
then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
begin
ForceDirectories(t);
end;
if sDirName[Length(sDirName)] <> '\' then
begin
DoCopyDir(sDirName+'\'+tfile,t);
end else begin
DoCopyDir(sDirName+tfile,t);
end; end else begin
t:=sToDirName+'\'+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until
FindNextFile(hFindFile,FindFileData) = False;
FindClose(hFindfile);
end else begin
ChDir(sCurDir);
Result:= True;
end;
ChDir(sCurDir);
Result:=true;
end;
写if FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY
找到目录也不认
写成if FindFileData.dwFileAttributes =2064就能判断是目录文件
还有就是加FindClose(hFindfile); 这句后编译不过以上两个问题为什么请帮我看看。
function TMainForm.DoCopyDir(sDirName, 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
begin
ForceDirectories(sToDirName);
end;
Memo1.Lines.Add('hFindFile <> INVALID_HANDLE_VALUE');
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
begin
Continue;
end;
//是目录文件的建立
if FindFileData.dwFileAttributes = 2064 //FILE_ATTRIBUTE_DIRECTORY
then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
begin
ForceDirectories(t);
end;
if sDirName[Length(sDirName)] <> '\' then
begin
DoCopyDir(sDirName+'\'+tfile,t);
end else begin
DoCopyDir(sDirName+tfile,t);
end; end else begin
t:=sToDirName+'\'+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until
FindNextFile(hFindFile,FindFileData) = False;
FindClose(hFindfile);
end else begin
ChDir(sCurDir);
Result:= True;
end;
ChDir(sCurDir);
Result:=true;
end;
解决方案 »
- 据说这个语言开发共享软件很不错。
- 人民币求助:虚拟仪表的实现源码
- 如何在DELPHI中编写一个接收参数的EXE文件。
- 关于曲线拟和的问题,高手赐教!!!!高分了!!!
- 迷茫,我到底该做什么?希望大家多多给意见?
- 帮我看一下我的ListView1怎么显示不了系统的图标
- dbgrid里的内容怎么导入到excel或者文本文件
- 我在自学Delphi,可是有许多不懂的地方,想多多的练习实例,可是没有呀,请问哪位大侠知道有下载的吗?
- 〓〓〓〓 请问谁有1stClass 3000的安装密码 〓〓〓〓
- 紧急求教
- 在adoquery的afterscroll事件中是不是不能用frpreview?
- 怎样设置ListView控件中某行记录文字的颜色或该行的颜色
procedure FindFile(Path: String);
var
hData: TWin32FindData;
hFile: THandle;
begin
hFile := FindFirstFile(PAnsiChar(Path + '\*.*'), hData);
if hFile <> INVALID_HANDLE_VALUE then
repeat
begin
{--- 屏蔽掉'.'和'..'目录 ---}
if (hData.cFileName[0] = '.') then
Continue;
{--- 若找到的是二级文件目录则在此目录下递归查找 ---}
if hData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
FindFile(Path + '\' + hData.cFileName)
else
{--- 若找到的是文件 ---}
begin
//进行你的操作,Copy也好,Path + '\' + hData.cFileName这是完整的文件名。
end;
end;
until not FindNextFile(hFile, hData)
else
begin
ShowMessage('This Path is Error!');
Exit;
end;
end;
// 设置文件拷备函数
function WinCOPY(SourceFileName: String; TargetFileName: String): String;
var
OpStruc: TSHFileOpStruct;
FromBuf,ToBuf: Array[0..128] of Char;
begin
FillChar(FromBuf,Sizeof(FromBuf),0);
FillChar(ToBuf,Sizeof(ToBuf),0);
//用0初始化FromBuf和ToBuf数组
StrPCopy(FromBuf,Pchar(SourceFileName));
StrPCopy(ToBuf,Pchar(TargetFileName));
//分别在 FromBuf和ToBuf数组中填入操作的源目录及目标目录
//开始填充OpStruc记录
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;
OpStR:= SHFileOperation(OpStruc);
end;
end;