http://expert.csdn.net/Expert/topic/2100/2100549.xml?temp=.6491205
中xiaoxiao197821(你的笑对我很重要) 兄的函数有点小问题 ,我用的是2000 professional,错误提示:
pathwithslash函数没找到;'filegetattr' is specific to a platform;
'fahidden' is specific to a platform;
'fareadonly' is specific to a platform;
'filesetattr' is specific to a platform;
是不是只能在win 98下用啊?
中xiaoxiao197821(你的笑对我很重要) 兄的函数有点小问题 ,我用的是2000 professional,错误提示:
pathwithslash函数没找到;'filegetattr' is specific to a platform;
'fahidden' is specific to a platform;
'fareadonly' is specific to a platform;
'filesetattr' is specific to a platform;
是不是只能在win 98下用啊?
TEnumDirectoryFileProc = procedure (Filename: string; var bContinue: Boolean);
procedure EnumDirectoryFiles(sDir, sMask: string; Attr: Integer; EnumDirectoryFileProc: TEnumDirectoryFileProc);
var
SearchRec: TSearchRec;
Status : Integer;
bContinue: Boolean;
begin
sDir := FullDirWithSlash(sDir);
Status := FindFirst(sDir + '*.*', faDirectory, SearchRec);
try //找所有的子目录
while Status = 0 do
begin
if (SearchRec.name <> '.') and (SearchRec.name <> '..') then
EnumDirectoryFiles(sDir + SearchRec.name, sMask, Attr, EnumDirectoryFileProc);
Status := FindNext(SearchRec);
end;
finally
SysUtils.FindClose(SearchRec);
end;
Status := FindFirst(sDir + sMask, faAnyFile, SearchRec);
try //处理指定目录下的所有文件(不包括子目录)
while Status = 0 do
begin
if (SearchRec.Attr and Attr <> 0) and
(FileExists(sDir + SearchRec.name) or DirectoryExists(sDir + SearchRec.name)) and
not ((SearchRec.Attr and faDirectory <> 0) and ((SearchRec.name = '.') or (SearchRec.name = '..'))) then
begin
bContinue := True;
EnumDirectoryFileProc(sDir + SearchRec.name, bContinue);
if not bContinue then Break;
end;
Status := FindNext(SearchRec);
end;
finally
SysUtils.FindClose(SearchRec);
end;
end;procedure CleanDirectoryProc(sFileName: string; var bContinue: Boolean);
var
Attr: Integer;
begin
Attr := FileGetAttr(sFileName);
Attr := (not faReadOnly) and Attr; // 设置文件的非只读属性
Attr := (not faHidden) and Attr; // 设置文件的非隐藏属性
FileSetAttr(sFileName, Attr); if Attr and faDirectory <> 0 then //如果sFileName是目录
RMDir(sFileName)//删除空的子目录
else
SysUtils.DeleteFile(sFileName);
end;procedure ClearPath(sPath:string);
var
MyPro:TEnumDirectoryFileProc;
begin
if sPath='' then
Exit;
MyPro:=CleanDirectoryProc;
EnumDirectoryFiles(sPath,'*.*', faAnyFile,MyPro);
//if DirectoryExists(sPath) then//删除你所传入的文件夹
//RemoveDir(sPath);
end;
begin
Result:=sDir;
if copy(sDir,Length(sDir),1)<>'\' then
Result:=Result+'\';
end;
不好意思,此函数只是一个加反斜杠的函数,我从我的单元中摘下来的,如果有什么地方没有说明白的,请继续!