想复制一个文件,此文件下有多个目录,但不想复制隐藏的文件用什么方法?我的代码如下: 怎样改??
//拷贝所有目录文件
Function MyUtil_CopyDirectory(SourceDir, TargetDir:pchar; Recursive:integer):integer;stdcall;
var
r:TSearchRec;
li_return : integer;
errorMessage: string;
begin
errorMessage := '';
if not DirectoryExists(TargetDir) then CreateDir(TargetDir);
try
if FindFirst(SourceDir+'*.*', faDirectory+faArchive, r)=0 then
repeat
if (r.Name<>'.') and (r.Name<>'..') then
if (r.Attr and faDirectory<>0) and (Recursive = 1) then
MyUtil_CopyDirectory(pchar(SourceDir+r.Name+'\'), pchar(TargetDir+r.Name+'\'), Recursive)
else
if r.Attr and faArchive<>0 then
//拷贝文件
CopyFile(PChar(SourceDir+r.Name), PChar(TargetDir+r.Name), False);
until FindNext(r)<>0;
li_return := 1;
except
on E: Exception do
begin
ErrorMessage := string(E.Message);
li_return := -1;
end;
end;
result := li_return;
end;
//拷贝所有目录文件
Function MyUtil_CopyDirectory(SourceDir, TargetDir:pchar; Recursive:integer):integer;stdcall;
var
r:TSearchRec;
li_return : integer;
errorMessage: string;
begin
errorMessage := '';
if not DirectoryExists(TargetDir) then CreateDir(TargetDir);
try
if FindFirst(SourceDir+'*.*', faDirectory+faArchive, r)=0 then
repeat
if (r.Name<>'.') and (r.Name<>'..') then
if (r.Attr and faDirectory<>0) and (Recursive = 1) then
MyUtil_CopyDirectory(pchar(SourceDir+r.Name+'\'), pchar(TargetDir+r.Name+'\'), Recursive)
else
if r.Attr and faArchive<>0 then
//拷贝文件
CopyFile(PChar(SourceDir+r.Name), PChar(TargetDir+r.Name), False);
until FindNext(r)<>0;
li_return := 1;
except
on E: Exception do
begin
ErrorMessage := string(E.Message);
li_return := -1;
end;
end;
result := li_return;
end;
解决方案 »
- IdTCPServer同时向多个Client发送不同文件?
- 如何打开这个Access(根据经验判断是Access文件)文件???
- 请教:自定义查询
- 100分,不会都入来看一下,UP都有分!
- DELPI7编写的动态库,在PB中如何声明
- 成心求教
- 新手碰到的问题
- 重贴“看看代码有什么错!帮帮忙好么?“
- 怎样获取大写键和NUM LOCK的状态?
- 请问如何实现菜单上实现右键菜单?
- 一打开dpr文件就出错Access violation at address 4000586A in module ‘rtl60.bpl’. Read of address 400A1004
- alter table bmdy alter column [Identity_bmdy] [numeric](18, 0) IDENTITY (1, 1) NOT NULL 错了???
do things you want.....pls have a try!
var DirInfo: TSearchRec;
DosError: Integer;
begin
DosError := FindFirst(SourceDir+'\*.*', faDirectory, DirInfo);
if not DirectoryExists(TargetDir) then
ForceDirectories(TargetDir);
while DosError=0 do
begin
if ((DirInfo.Attr and FaDirectory)=faDirectory) and (DirInfo.Name<>'.') and (DirInfo.Name<>'..')
then XCopyDir(SourceDir + '\' + DirInfo.Name, TargetDir + '\' + DirInfo.Name);
{$IF DEFINED(WIN32) AND DECLARED(UsingVCL)}
if ((DirInfo.Attr and FaDirectory)<>FaDirectory) and ((DirInfo.Attr and FaVolumeID)<>FaVolumeID)
{$ELSE}
if ((DirInfo.Attr and FaDirectory)<>FaDirectory)
{$IFEND}
then CopyFile(PChar(SourceDir + '\' + DirInfo.Name), PChar(TargetDir + '\' + DirInfo.Name), false);
DosError := FindNext(DirInfo);
end;
SysUtils.FindClose(DirInfo);
end;
//终于解决了