Here was my answer 😀
Create a New | C++Builder VCL Windows application. On the form add TPanel, TButton, TEdit and TMemo components. Put the TButton and TEdit into the TPanel. Set TPanel align property to AlTop. Set the TMemo align property to alClient.
FindFirst’s declaration in SysUtils.hpp is:
1 |
extern DELPHI_PACKAGE int __fastcall FindFirst(const System::UnicodeString Path, int Attr, TSearchRec &F); |
The key point is to included any or all of the file attributes (integer parameter Attr) for files that you want to find. The file attribute choices are defined in “C:\Program Files (x86)\Embarcadero\Studio\21.0\include\windows\rtl\windows\rtl\System.SysUtils.hpp”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
static const System::Int8 faInvalid = System::Int8(-1); // Identifies an invalid file. static const System::Int8 faReadOnly = System::Int8(0x1); // Identifies read-only files or directories. static const System::Int8 faHidden = System::Int8(0x2); // Identifies hidden files or directories. static const System::Int8 faSysFile = System::Int8(0x4); // Identifies system files or directories. static const System::Int8 faVolumeID _DEPRECATED_ATTRIBUTE0 = System::Int8(0x8); // Deprecated static const System::Int8 faDirectory = System::Int8(0x10); // Identifies a directory. static const System::Int8 faArchive = System::Int8(0x20); // Identifies Windows archived files. static const System::Byte faNormal = System::Byte(0x80); // Identifies normal files. static const System::Word faTemporary = System::Word(0x100); // Identifies temporary files or directories. static const System::Word faSymLink = System::Word(0x400); // Specifies only symbolic link file types. static const System::Word faCompressed = System::Word(0x800); // Identifies a compressed file or directory. static const System::Word faEncrypted = System::Word(0x4000); // Identifies an encrypted file or directory. static const int faVirtual = int(0x10000); // Reserved for system use. static const System::Word faAnyFile = System::Word(0x1ff); // Specifies any file type. |
The following code will display all items in a directory including the ., .., .~* files – for example in a C++Builder project’s history folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
void __fastcall TForm1::Button1Click(TObject *Sender) { TSearchRec sr; Memo1->Lines->Clear(); int iAttributes = 0; iAttributes |= faReadOnly; iAttributes |= faHidden; iAttributes |= faSysFile; iAttributes |= faVolumeID; iAttributes |= faDirectory; iAttributes |= faArchive; iAttributes |= faAnyFile; if (FindFirst(Edit1->Text, iAttributes, sr) == 0) { do { if ((sr.Attr & iAttributes) == sr.Attr) { Memo1->Lines->Add( sr.Name + " = " + IntToStr(sr.Size) ); } } while (FindNext(sr) == 0); FindClose(sr); } } |
I put the string: C:\Users\david\Documents\Embarcadero\Studio\Projects\CBuilder\FindFirstVCLCpp\__history\*.* in the EditBox. After clicking the Button, the TMemo contained the following contents.
References
To find more C++Builder StackOverflow questions and answers use the C++Builder SO Tag 😀
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition