小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

判斷文件夾下子文件夾是否為空

 獨(dú)孤求財(cái) 2012-03-20

判斷文件夾下子文件夾是否為空

時(shí)間:2011-5-26來(lái)源:yang 作者: peng點(diǎn)擊: 19次

unit unDirOption;

interface
  uses SysUtils, Classes;

 //查當(dāng)前文件夾下的所有子文件
 procedure SearchFile(DirName: String; var sList: TStrings);
 //判斷文件夾是否為空
 function IsEmptyDir(sDir: String): Boolean;
 //判斷字符串是否為數(shù)字
 function IsNumber(sStr: String): Boolean;
 //刪除文件夾
 procedure DeleteDir(sDirectory: String);
 {
   執(zhí)行刪除文件夾操作
   sFileName -> 要掃描的文件夾路徑  sList -> 用至裝載將掃描到的文件夾
   iDay -> 區(qū)別是掃10個(gè)字符還是8個(gè)字符 (超速是8個(gè),過(guò)往車(chē)輛是10個(gè))
   iAgoDay -> 要?jiǎng)h除多少天前的記錄
 }
 procedure ExecuteDeleteDir(Const sFileName: String; var sList: TStrings;
   iDay, iAgoDay: Integer);

 //遍歷文件夾及子文件夾的文件
 function MakeFileList(Path,FileExt:string):TStringList ;

var
    MyFileName: string;

implementation

procedure SearchFile(DirName: String; var sList: TStrings);
Var
  Found: integer;
  SearchRec: TSearchRec;
begin
  Found := FindFirst(DirName + ‘*.*‘,faAnyFile,searchrec);
  while Found = 0 do
  begin
    if ((SearchRec.Attr and faDirectory)<>0) then  //directory
    begin
      if(SearchRec.Name <> ‘.‘)and(SearchRec.Name <> ‘..‘) then
      begin
        SearchFile(DirName + SearchRec.Name + ‘\‘, sList);
        MyFileName := DirName + SearchRec.Name;
        sList.Insert(0, MyFileName);
      end;
    end;
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

procedure ExecuteDeleteDir(Const sFileName: String; var sList: TStrings;
  iDay, iAgoDay: Integer);
var
  I: Integer;
  LastDir: String; //文件夾最后幾個(gè)字符
  DirDate: String;//當(dāng)前文件夾的日期
begin
  SearchFile(sFileName, sList);
  for I := 0 to sList.Count - 1 do
  begin
    if iDay = 10 then    
      LastDir := copy(sList.Strings[i],length(sList.Strings[i])-9,10)
    else LastDir := copy(sList.Strings[i],length(sList.Strings[i])-9,8);
    if IsNumber(LastDir) then
    begin
      DirDate := copy(sList.Strings[i],length(sList.Strings[i])-9,8);
      //此處將字符串轉(zhuǎn)為日期格式
      DirDate := Copy(DirDate,1,4) + ‘-‘ + Copy(DirDate,5,2) + ‘-‘ + Copy(DirDate,7,2);
      if StrToDate(DirDate) < Date - iAgoDay  then  //進(jìn)行條件篩選
      begin
        //判斷文件夾是否為空
        //if IsEmptyDir(sList.Strings[i]) then
          DeleteDir(sList.Strings[i]);
      end;
    end;
  end;
end;

function IsEmptyDir(sDir: String): Boolean;
var
  sr: TsearchRec;
begin
  Result := True;
  if Copy(sDir, Length(sDir) - 1, 1) <> ‘\‘ then sDir := sDir + ‘\‘;
  if FindFirst(sDir + ‘*.*‘, faAnyFile, sr) = 0 then
    repeat
      if (sr.Name <> ‘.‘) and (sr.Name <> ‘..‘) then
      begin
        Result := False;
        break;
      end;
    until FindNext(sr) <> 0;
  FindClose(sr);
end;

function IsNumber(sStr: String): Boolean;
var
  i,iLength: integer;
begin  
  iLength := Length(sStr);
  for i := 1 to iLength do
  begin  
    if not (sStr[i] in [‘0‘..‘9‘]) then
    begin
      Result   :=   false;
      exit;
    end  
  end;  
  Result := true;  
end;  

procedure DeleteDir(sDirectory: String);
//刪除目錄和目錄下得所有文件和文件夾
var
  sr: TSearchRec;
  sPath,sFile: String;
begin
  //檢查目錄名后面是否有 ‘\‘
  if Copy(sDirectory,Length(sDirectory),1) <> ‘\‘ then
  sPath := sDirectory + ‘\‘
  else
  sPath := sDirectory;

  //------------------------------------------------------------------
  if FindFirst(sPath+‘*.*‘,faAnyFile, sr) = 0 then
  begin
  repeat
  sFile:=Trim(sr.Name);
  if sFile=‘.‘ then Continue;
  if sFile=‘..‘ then Continue;

  sFile:=sPath+sr.Name;
  if (sr.Attr and faDirectory)<>0 then
  DeleteDir(sFile)
  else if (sr.Attr and faAnyFile) = sr.Attr then
  DeleteFile(sFile); //刪除文件
  until FindNext(sr) <> 0;
  FindClose(sr);
  end;
  RemoveDir(sPath);
  //------------------------------------------------------------------
end;

{
//調(diào)用方法
 MakeFileList(‘c:\‘, ‘.ini‘);
}
//遍歷文件夾中的文件
function MakeFileList(Path,FileExt:string):TStringList ;
var
  sch:TSearchrec;
begin
  Result:=TStringlist.Create;
  if rightStr(trim(Path), 1) <> ‘\‘ then
    Path := trim(Path) + ‘\‘
  else
    Path := trim(Path);

  if not DirectoryExists(Path) then
  begin
    Result.Clear;
    exit;
  end;

  if FindFirst(Path + ‘*‘, faAnyfile, sch) = 0 then
  begin
    repeat
       Application.ProcessMessages;
       if ((sch.Name = ‘.‘) or (sch.Name = ‘..‘)) then Continue;
       if DirectoryExists(Path+sch.Name) then
       begin
         Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
       end
       else
       begin
         if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt=‘.*‘) then
         Result.Add(Path+sch.Name);
       end;
    until FindNext(sch) <> 0;
    SysUtils.FindClose(sch);
  end;
end;

end.

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多