zoukankan      html  css  js  c++  java
  • FindFirst,FindNext,FindClose学习

    procedure TForm1.Button1Click(Sender: TObject);
    var
    Dir: TSearchRec; //文件结构
    begin
    if FindFirst(edit1.Text,faAnyFile,Dir) = 0 then
    begin
    repeat
    //是目录吗?
    //and 的作用是通过 "与" fadirectory 消掉Attr中的其它文件,只取留下faDirectory属性
    //通过 or 可以添另其它属性
    if(Dir.Attr and faDirectory) = faDirectory then
    begin
    ListBox1.Items.Add(dir.Name);
    if (dir.Name <> '.') and (dir.name <> '..') then
    GetSubDir('','D:\'+dir.Name,5,true);
    end;
    until (FindNext(Dir) <> 0);
    end;
    FindCLose(Dir);
    end;

    procedure TForm1.GetSubDir(Filter, Folder: string;TreeLevel:Integer; Recurse: boolean);
    var
    Dir: TSearchRec;
    count :Integer;
    begin
    count := 0;
    Folder :=IncludeTrailingPathDelimiter(Folder);

    if FindFirst(Folder+'*.*',faDirectory,Dir) = 0 then
    begin
    repeat
    //是目录吗?
    //and 的作用是通过 "与" fadirectory 消掉Attr中的其它文件,只取留下faDirectory属性
    //通过 or 可以添另其它属性
    if(Dir.Attr and faDirectory) = faDirectory then
    begin
    if (dir.Name <> '.') and (dir.name <> '..') then
    begin
    inc(count); //文件深度count

    if(count > TreeLevel) then
    break;

    ListBox1.Items.Add(dir.Name);

    if Recurse then
    GetSubDir('',Folder+dir.Name,2,Recurse); //递归调用获取子目录
    end;
    end;
    until (FindNext(Dir) <> 0);
    end;
    FindCLose(Dir);
    end;
  • 相关阅读:
    【JOI2017春季合宿】Port Facility
    LOJ504「LibreOJ β Round」ZQC 的手办
    UOJ37. 【清华集训2014】主旋律
    CF1012F Passports
    AT2370 Piling Up
    CF908G New Year and Original Order
    CF643E Bear and Destroying Subtrees
    CF183D T-shirt
    「JOISC 2016 Day 3」回转寿司
    「LibreOJ β Round #2」计算几何瞎暴力
  • 原文地址:https://www.cnblogs.com/pengshaomin/p/2343047.html
Copyright © 2011-2022 走看看