Article View: borland.public.cppbuilder.nativeapi
Article #857Re: Getting directory file names in builder 5
From: Michael Corby
Date: Mon, 10 Dec 2007 18:22
Date: Mon, 10 Dec 2007 18:22
114 lines
4695 bytes
4695 bytes
"tom" <No@noemail.net> wrote in message
news:475cb157@newsgroups.borland.com...
> Haven't been here in awhile and haven't used bcb5 in awhile either.
> What I would like to know is how can I get a listing of file names from a
> given directory in bcb5? Seems to me I did it before but for the life of
> me I can't remember how or in what program I did it.
> Any way does has this command: dir /b MyDirName > temp.txt This
> reads all the names in MyDirName and puts them into a text file. I
> remembered this from the dos days, and looking back in old books. Is ther
> a way in BCB5. thanks for any help.
>
Hi Tom
Code taken from one of my test programs :-
void __fastcall TwThirdForm::bDirListClick(TObject *Sender)
{
String path, fileFilter, fullPathAndFilter, fileName, lines, header;
String output;
int index, size, txtLen;
TSearchRec searchRec;
index = DirectoryListBox1->ItemIndex;
path = DirectoryListBox1->GetItemPath(index) + "\\";
fileFilter = wThirdForm->eFilter->Text;
txtLen = fileFilter.Length();
if (txtLen == 0) { fileFilter = "*.*"; } // All Files
else { fileFilter = "*." + fileFilter; }
fullPathAndFilter = path + fileFilter;
// Clear items from ComboBox List and Memo
rProcsRunning->bStringBand->Items->Clear(); // Quick Report
wThirdForm->Memo1->Lines->Clear();
header = "List Sub-Directories and Files in Directory - " + path;
wThirdForm->Memo1->Lines->Add(header);
lines = "";
wThirdForm->Memo1->Lines->Add(lines);
// Get Directories
if (FindFirst(fullPathAndFilter, faDirectory, searchRec) == 0);
{
if (searchRec.Attr == faDirectory && faDirectory == faDirectory)
{
fileName = String(searchRec.Name);
if (fileName != "." && fileName != "..")
{
lines = "Directory - " + fileName;
wThirdForm->Memo1->Lines->Add(lines);
rProcsRunning->bStringBand->Items->Add(lines);
}
}
}
// Get Remainder of Directories
while (FindNext(searchRec) == 0)
{
if (searchRec.Attr == faDirectory && faDirectory == faDirectory)
{
fileName = String(searchRec.Name);
if (fileName != "." && fileName != "..")
{
lines = "Directory - " + fileName;
wThirdForm->Memo1->Lines->Add(lines);
rProcsRunning->bStringBand->Items->Add(lines);
}
}
}
// Close - always required after FindFirst/FindNext
FindClose(searchRec);
// Get Files
FileListBox1->Directory = fullPathAndFilter;
size = FileListBox1->Items->Capacity; // num files in directory
for(int i=0; i<size; i++)
{
FileListBox1->ItemIndex = i; // set index in filelist to i
fileName = FileListBox1->FileName; // absolute path of file
// Extract File Name only
output = ExtractFileName(fileName);
wThirdForm->Memo1->Lines->Add(output);
rProcsRunning->bStringBand->Items->Add(output);
}
// Report Header Details
rProcsRunning->ReportDescription->Caption = header;
// Report Date
rProcsRunning->DateOfReport->Caption = DateOfReport(); // This is a
function
// Preview is not Modal - so disable calling form
wThirdForm->Enabled = false;
rProcsRunning->Report->PreviewWidth = 720;
rProcsRunning->Report->PrevShowSearch = false;
rProcsRunning->Report->PrevShowThumbs = false;
rProcsRunning->Report->PrevFormStyle = fsNormal;
rProcsRunning->Report->Preview();
// Enable calling form
wThirdForm->Enabled = true;
}
//---------------------------------------------------------------------------
I hope you can pick up what you need from this.
Michael Corby
Technical Details
Message-ID:
<475d83f4$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<475cb157@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,3b8df2facea4c3de X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Michael Corby" <mcorby@sapo.pt> Newsgroups: borland.public.cppbuilder.nativeapi References: <475cb157@newsgroups.borland.com> Subject: Re: Getting directory file names in builder 5 Date: Mon, 10 Dec 2007 18:22:01 -0000 Lines: 116 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 85.243.128.33 Message-ID: <475d83f4$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1197310964 85.243.128.33 (10 Dec 2007 10:22:44 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail