1。肯定是要用递归函数
2。肯定要用到有关文件目录的Windows API
3. 我查阅过一些资料,是可以实现的,但是如此经典的编程思想我想肯定有最短
代码就能实现的方法。希望讨论一下,有技术含量的都有分。

解决方案 »

  1.   


    伪DELPHI代码,描述如下:
    procedure filescan()
    begin
    process files in current folder
    if current_folder containg subfolders then
    for i:=0 to subfolder.count do
    begin
        swetch to subfolder;
        filescan(); 
    end;
    move to parent directory;
    end;
    有什么问题发消息给我:)!
    好运!!!
      

  2.   

    转自delphibbs一个函数,结果用参数foundresult返回:
    function SearchFile(mainpath:string;filename:string; var foundresult:TStrings):Boolean;
    var
     i:integer;
     Found:Boolean;
     subdir1:TStrings;
     searchRec:TsearchRec;
    begin
      if right(mainpath,1)<>'\' then mainpath:=mainpath+'\';
      found:=false;
      if Trim(filename)<>'' then
      begin
        subdir1:=TStringList.Create;
        if (FindFirst(mainpath+'*.*', faDirectory,SearchRec)=0) then
        begin
          if IsValidDir(SearchRec) then subdir1.Add(SearchRec.Name);
          while (FindNext(SearchRec) = 0) do
          begin
            if IsValidDir(SearchRec) then subdir1.Add(SearchRec.Name);
          end;
      end;
      FindClose(SearchRec);
      //查找当前目录。
      if (FindFirst(mainpath+'*.*', faAnyFile-faDirectory, SearchRec)=0)  then
      begin
        foundresult.Add(mainpath+SearchRec.Name);
        while (FindNext(SearchRec) = 0) do
        begin
          foundresult.Add(mainpath+SearchRec.Name);
        end;
      end;
      FindClose(SearchRec);
      for i:=0 to subdir1.Count-1 do
        found:=Searchfile(mainpath+subdir1.Strings[i]+
    '\',Filename,foundresult)or found;
      subdir1.Free;
      end;
      result:=found;
    end;
      

  3.   

    //在论坛里搜索了很多,都用到什么chdir,都不好用,
    //所以自己写个最简洁的贡献出来。function Deltree(sDir: string): Boolean;
    var
            hFindFile: HWND;
            FindFileData: WIN32_FIND_DATA;
            sr: TSearchRec;
    begin
            sDir:= sDir + '\';        hFindFile:= FindFirstFile(pchar(sDir + '*.*'), FindFileData);
            if hFindFile <> NULL then
            begin
                    while FindNextFile(hFindFile, FindFileData) <> FALSE do
                    begin
                            if FindFileData.dwFileAttributes in [FILE_ATTRIBUTE_DIRECTORY] then
                            begin
                                    if (strpas(FindFileData.cFileName) <> '.') and (strpas(FindFileData.cFileName) <> '..') then
                                    begin
                                            Deltree(sDir + FindFileData.cFileName);
                                    end;
                            end
                            else begin
                                    deletefile(sDir + FindFileData.cFileName);
                            end;
                    end;
            end;
            sr.FindHandle:= hFindFile;
            FindClose(sr);
            RemoveDir(sDir);
    end;