IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Single User Apps Topic   Print This     

Can anybody help me with getti...

Can anybody help me with getti... in Delphi Single User Apps topic (part of our Pascal and Delphi Coding group).

Quick Search: anybody   Can anybody   Can anybody me   getti   
owen.moore
Ashburton, -- NZ

Can anybody help me with getting a directory file listing into a listbox so that I can programatticlly go through the listbox and put the filenames into a database

they Database part is not causing me any trouble

I can get it into  a dirlistbox but can not use that to then post certain of the file names to the Database

any help is most appreciated

Owen

 Posted 11 years ago (Thread Starter)
Comment Quote
About owen.moore -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #14145, 1 replies
Thread Started 6/7/2010 1:14:20 AM
View Counter=3707
Last Reply Posted 7/1/2010 1:46:08 PM)
Location=Ashburton, -- NZ 
Joined=18 years ago   MB Posts=7  
Most Recent Post
Rodney.N
West Hills, -- UNK

Owen,

Interesting question. The below code will add file names (excluding paths), except for directories and system files. See the comments. And only the files in the directory specified, this routine doesn't go into subdirectories.

Hope this is useful to you. let me know if it answers your query.

  FindAll('c:\*.*', faAnyFile, lbxFileList.Items)
 
{==============================================================================
  AUTHOR      :  Rodney Nicholls
  ATTRIBUTION :  Derived from code demo on About.com Delphi Programming
 ==============================================================================
  DESCRIPTION :  List files in the path argument.
                 Path must be stated as pathname\*.*
                 Directories and system files will not be listed. If you want
                 to list these then remove the lines indicated below.
                 If you don't need to list items in a listbox change the List
                 parameter to a TStringList.

 ==============================================================================
  CREATED     :  06/28/10
  HISTORY     :
  Date     Who   Comments
  -------- ----  -------------------------------------------------------------
 ==============================================================================}
procedure FindAll(const Path: String; Attr: Integer; List: TStrings);
var
  Res: TSearchRec;
  EOFound: Boolean;
  LFileAttributes: TFileAttributes;  // Remove if you want to list directories and system files
  FileName: string; // Remove if you want to list directories and system files
begin
  EOFound := False;

  if FindFirst(Path, Attr, Res) < 0 then
    Exit
  else
    while not EOFound do
    begin
      { Uncomment this line if you want to list directories and system files as well. }
      // List.Add(Res.Name);

      { Comment out the try...finally...end block if you want to list directories and system files as well. }
      try
        FileName := LeftStr(Path, Length(Path)-3) + Res.Name;

        { Note that this will throw an error if the file is a directory or a
          system file with a '.sys' directory. The error is trapped in the except section and thrown away allowing the next fiel to be found.}
        LFileAttributes := TFile.GetAttributes(FileName);
        List.Add(Res.Name);
      except
        { Throwaway exception }
      end;

      EOFound := FindNext(Res) <> 0;
    end;

  FindClose(Res);
end; { procedure TfrmFindFiles.FindAll }

Good luck

Rodney

 Posted 11 years ago
Comment Quote
About Rodney.N -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #14204 (Level 1.1)  Reply to 14145
Thread Started 7/1/2010 1:38:28 PM
Location=West Hills, -- UNK 
Joined=11 years ago   MB Posts=1  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1204A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #14145 Counter
3707
Since 6/7/2010
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2021 Prestwood IT Solutions.   [Security & Privacy]