Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

Text Files

Hi,

I need to write a program that gets the names of the files within a certain folder.
A folder will be named and a series of .csv files located within.
I need to be able to get the names of these files and store them in a list so that
I can read through them and do some other stuff.
I have looked at the 'SelectDirectory' function but I dont think this does what I require.

Any help would be great,
Many Thanks
0
HotRod40
Asked:
HotRod40
1 Solution
 
ITugayCommented:
here is a sample.

drop TEdit (Edit1) on form and enter path there


procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  F: TSearchRec;
begin
  if FindFirst(Edit1.Text + '*.csv', faAnyFile, F) = 0 then
  repeat
    ListBox1.Items.Add(Edit1.Text + F.Name);
  until FindNext(F) <> 0;
  FindClose(F);
end;

-----
Igor
0
 
HotRod40Author Commented:
Once these files are in a list box, is there a way that I can loop through the listbox and view the current filename of each iteration.

Ive tried the following but it doesnt work:

var
  i: integer;
  filename: string;
begin
  for i := 0 to lstFiles.SelCount - 1 do
  begin
    filename := lstFiles.Items[lstFiles.ItemIndex];
    ShowMessage(filename);
  end;
end;

Many Thanks
0
 
NoturnoCommented:
For give me for my poor english (i'm brazilian)

To see all selected items in this listbox:

var
 i: integer;
 filename: string;
begin
 for i := 0 to lstFiles.SelCount - 1 do
 begin
   filename := lstFiles.Selected[i];
   ShowMessage(filename);
 end;
end;

To see ALL items in the listbox, put Items.Count instead of SelCount and Items[i] instead of Selected[i] (:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now