Recent

Author Topic: Reading a directory list of files into an array of string;  (Read 16668 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #15 on: January 21, 2018, 07:36:20 pm »
Where or how are you getting btnShowClick?
Both you and Aserge have it.

I don't see it in properties or events of a button or a Fourm1

procedure TForm1.btnShowClick(Sender: TObject);

« Last Edit: January 21, 2018, 08:20:06 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Reading a directory list of files into an array of string;
« Reply #16 on: January 21, 2018, 07:40:54 pm »
1. Create a BUTTON and name it btnShow.
2. Go to the BUTTON events and doubleclick on OnClick.

LAZARUS creates a procedure for you ....
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #17 on: January 21, 2018, 07:46:17 pm »
1. Create a BUTTON and name it btnShow.
2. Go to the BUTTON events and doubleclick on OnClick.

LAZARUS creates a procedure for you ....

When you know how to do this stuff it's easy. Just a lot to consume.

I did make a change of CBX to CBX:=1 to force it to go there.

I don't need or want sub-directories searched.
I'll work on it.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #18 on: January 21, 2018, 08:19:42 pm »
I now have it back to ASerge original
I have a named btnShowClick and CBXHidden.
I added a TListBox and named it edtDirectory.

It dosen't like the edtDirectory.Text (See the last two lines in Red)

procedure TForm1.btnShowClick(Sender: TObject);
     var
          ListOfFiles: TStringList;
          ListOfFolders: TStringList;
          Attributes: Integer;
          Message: string;

begin

      Attributes := faReadOnly;
      if cbxHidden.Checked then
        Attributes := Attributes or faHidden;
      ListOfFiles := TStringList.Create;
      try
        FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*', False, Attributes);
        ListOfFiles.Insert(0, Format('The directory contains %d file(s).', [ListOfFiles.Count]));
        Message := ListOfFiles.Text;
      finally
        ListOfFiles.Free;
      end;
      if cbxHidden.Checked then
      begin
        ListOfFolders := TStringList.Create;
        try
          FileUtil.FindAllDirectories(ListOfFolders, edtDirectory.Text, False);
          ListOfFolders.Insert(0, Format('And %d folders(s).', [ListOfFolders.Count]));
          Message := Message + ListOfFolders.Text;
        finally
          ListOfFolders.Free;
        end;
      end;
      ShowMessage(Message)
end;
                                                                   


Compile Project, Target: project1.exe: Exit code 1, Errors: 2, Warnings: 1
unit1.pas(49,45) Warning: Symbol "faHidden" is not portable
unit1.pas(52,57) Error: identifier idents no member "Text"
unit1.pas(62,67) Error: identifier idents no member "Text"
« Last Edit: January 21, 2018, 08:26:01 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Reading a directory list of files into an array of string;
« Reply #19 on: January 21, 2018, 08:29:38 pm »
edtDirectory is a TEdit (edt means edit). So remove the TListBox, add a TEdit and name it edtDirectory.

Not always but usually:
edt.... -> TEdit
cbx.... -> TCheckBox or TComboBox
btn.... -> TButton
lbl.... -> TLabel
« Last Edit: January 21, 2018, 08:36:16 pm by Handoko »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #20 on: January 21, 2018, 08:59:42 pm »
edtDirectory is a TEdit (edt means edit). So remove the TListBox, add a TEdit and name it edtDirectory.

Not always but usually:
edt.... -> TEdit
cbx.... -> TCheckBox or TComboBox
btn.... -> TButton
lbl.... -> TLabel

I don't find a TEdit.
There is a TFileListbox and I tried it. Didn't work. It was under MISC.
Is this a new control maybe I don't have?
Under MISC there were a lot of controls that started with T.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Reading a directory list of files into an array of string;
« Reply #21 on: January 21, 2018, 09:53:18 pm »
Quote
Is this a new control maybe I don't have?
Nope .... Not really...  :)

Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #22 on: January 21, 2018, 10:19:55 pm »
 :D

Got it compiled and ran.

Popup message said:

project1

The directory contains 0 file(s).

I think maybe I need to set the Dir path somewhere or a mask but now that it compiles and runs I can work on it.

Thanks.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Reading a directory list of files into an array of string;
« Reply #23 on: January 22, 2018, 04:01:05 am »
Just my guess, you can try:

Change this line:
Attributes := faReadOnly;
To
Attributes := faReadOnly or faArchive;

And also:
FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*', False, Attributes);
To:
FileUtil.FindAllFiles(ListOfFiles, edtDirectory.Text, '*.*', False, Attributes);

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Reading a directory list of files into an array of string;
« Reply #24 on: January 22, 2018, 06:38:26 am »
Ok - Progress Update:
There are 20 possible file extensions but ,rte and RTE double up.

Modified the following in uAirUtils based on the following extensions:

// Updated with new and corrected extension
// pe_route, com, efbr, fpl, flp, fmc, gfp, in, mdr, pln, rte, route, RTE
// sbr, sbp, sfp, txt, ufmc, vfp,,wx, xml


  TPlanExtension = (pe_route, peCom, peEfbr, peEbr,  peFpl,  peFlp,  peFmc,
                    peGfp,    peIn,  peMdr,  pePln,  peRte,  peSbr,  peSbp,
                    peSfp,    peTxt, peUfmc, peVfp,  peWx,   peXml,
                    peUnknown);


// Updated with new and corrected extension
// pe_route, com, efbr, fpl, flp, fmc, gfp, in, mdr, pln, rte, route, RTE
// sbr, sbp, sfp, txt, ufmc, vfp,,wx, xml
function TPlanExtensionToStr(aPlanExtension: TPlanExtension): String;
begin
  case aPlanExtension of
    pe_route  :    Exit('');
    peCom     :    Exit('.com');
    peEfbr     :    Exit('.efbr');
    peFpl      :     Exit('.fpl');
    .
    .
    .
           
// Updated with new and corrected extension
// pe_route, com, efbr, fpl, flp, fmc, gfp, in, mdr, pln, rte, route,
// sbr, sbp, sfp, txt, ufmc, vfp,,wx, xml
function IsValidPlanFilename(aFilename: String): Boolean;
begin
  case LowerCase(ExtractFileExt(aFilename)) of
    '':   if Copy(aFilename, Length(aFilename)-5, 6) = '_route' then
            Exit(True)
          else
                Exit(False);
    '.com'    : Exit(True);
    '.efbr'   : Exit(True);
    '.fpl'    : Exit(True);
    '.flp'    : Exit(True);
    '.fmc'    : Exit(True);
    .               
    .
    '


Changed everything to   acAivlaSoftEFB: Exit('C:\X-Plane 11\OUTPUT\FMS Plans');
Needs more work to assign the right path based on extintion and.or aircraft.



Needs more work to assign the right path based on extensions and.or aircraft.[/color][/b]
function TFlightPlan.GetDestFolder: String;
begin
  // pe_route, com, efbr, fpl, flp, fmc, gfp, in, mdr, pln, rte, route, RTE
  // sbr, sbp, sfp, txt, ufmc, vfp,,wx, xml
   case GetExtension of

    pe_route: case aircraft of
                   acAivlaSoftEFB: Exit('C:\X-Plane 11\OUTPUT\FMS Plans');
               else Exit('');
              end;

    peCom: case aircraft of
                   acAivlaSoftEFB: Exit('C:\X-Plane 11\OUTPUT\FMS Plans');
               else Exit('');
              end;

     peEfbr: case aircraft of
                   acAivlaSoftEFB: Exit('C:\X-Plane 11\OUTPUT\FMS Plans');
               else Exit('');
              end;

     peFpl: case aircraft of
                   acAivlaSoftEFB: Exit('C:\X-Plane 11\OUTPUT\FMS Plans');
               else Exit('');
              end;
  .
  .
  .

// Updated with new and corrected extension
// pe_route, com, efbr, fpl, flp, fmc, gfp, in, mdr, pln, rte, route, RTE
// sbr, sbp, sfp, txt, ufmc, vfp,,wx, xml
function TFlightPlan.GetExtension: TPlanExtension;
begin
  case LowerCase(ExtractFileExt(downloadFilename)) of
    '':   if Copy(downloadFilename, Length(downloadFilename)-5, 6) = '_route' then
            Exit(pe_route)
          else
            Exit(peUnknown);
       '.com'    : Exit(peCom);
       '.efbr'   : Exit(peEfbr);
       '.fpl'    : Exit(peFpl);
       '.flp'    : Exit(peFlp);
       '.fmc'    : Exit(peFmc);
       '.in'     : Exit(peIn);
       '.mdr'    : Exit(peMdr);
  .
  .
  .
The MainForm looks good.

Maybe we need a second form to set thing like:
Current AIRAC Cycle installed.
Path where you want MasterFlightPlans Directory created.
Path to all the simulators they want installed.
Save it to an .ini or .txt file.
In X-Plane 11 we have several .ini files.

                                               
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Handoko

  • Hero Member
  • *****
  • Posts: 5151
  • My goal: build my own game engine using Lazarus
Re: Reading a directory list of files into an array of string;
« Reply #25 on: January 22, 2018, 06:55:32 am »
Glad to hear you managed to make some progress.

Here is the info about how to use .ini files for saving program settings:
http://wiki.freepascal.org/Using_INI_Files

 

TinyPortal © 2005-2018