Board index » delphi » Getting dirs/files into a txt file for a tree window

Getting dirs/files into a txt file for a tree window

Does anyone know how to get a program to scan a hard drive and write a text
file that will show all the folders and files on a selected hard drive and
make it so the txt file is easily openable with a tree thing. I want it like
the directory outline in delphi 2 (what i use) but to also show the files
available.
Any ideas towards how i may do this will be appreciated.
Thanx
    Dan
 

Re:Getting dirs/files into a txt file for a tree window


Hi

Maybe this will help (untested):
procedure TForm1.GetFilesFrom(APath:string; var ListBox: TListBox);
var   TempRes :Integer; //stores our temporary result
      SR      :TSearchRec; //stores info about current file
      FileLst : TStringList;
begin
   //Find the first file and set search options
   TempRes:=FindFirst(APath+'\*.*',faAnyFile, SR);

   //iterate through the filelist
   while TempRes=0 do
   begin
      //lets make sure we won't select the previous directory
      if (SR.Name<>'.') and (SR.Name<>'..') then
         //if we have found a directory
         if (SR.Attr and faDirectory > 0) then
            //we search this directory recursively
            GetFilesFrom(APath+'\'+SR.Name, ListBox)
         else
            //otherwise we add the file to the string list
            FileLst.Add(APath + '\' + SR.Name);

      //proceed to next file
      TempRes:=FindNext(SR);
   end;

   //Free resources
   FindClose(SR);

   //save file list
   FileLst.SaveToFile('MyFileLst.txt'); //or whatever
end; //procedure TForm1.GetFilesFrom

Hope this helps. Write me if it don't

Regards
Toft

In article <8ciu9f$lh...@neptunium.btinternet.com>,
  "Dan" <Gazan...@btinternet.com> wrote:

Quote
> Does anyone know how to get a program to scan a hard drive and write
a text
> file that will show all the folders and files on a selected hard
drive and
> make it so the txt file is easily openable with a tree thing. I want
it like
> the directory outline in delphi 2 (what i use) but to also show the
files
> available.
> Any ideas towards how i may do this will be appreciated.
> Thanx
>     Dan

--
Life is for the living. I like it.
sunb...@worldonlineNOSPAM.dk
Remove NOSPAM to mail me

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads