Greetings to all of you programmer gurus…! =)
Can some one please help me refine this code??
Its intention is to search a folder (included sub directories) for files / folders and store it in a file saved to disk (i.e. C:\test.txt)
The parts I want to remove mostly are those dealing with TRichEdit… Need something else!! I'm tired of using TRichEdit for my programs…! =/
What else but TRichEdit can I use??
The code below are my own, and created entirely by me (with help from others, 2ffat for instance), however, you can copy it (freely) and use it for own purpose!!
Thanks for any idea…
Martin G Broman
mgb_svea@thevortex.com
DWS - Alpha Whitin Dead Wolf Society
Can some one please help me refine this code??
Its intention is to search a folder (included sub directories) for files / folders and store it in a file saved to disk (i.e. C:\test.txt)
The parts I want to remove mostly are those dealing with TRichEdit… Need something else!! I'm tired of using TRichEdit for my programs…! =/
What else but TRichEdit can I use??
The code below are my own, and created entirely by me (with help from others, 2ffat for instance), however, you can copy it (freely) and use it for own purpose!!
Code:
#include <dos.h>
#include <dir.h>
void __fastcall TForm1::scan_it(TObject *Sender)
{
/*frag*/
struct ffblk ffblk; // Structure for file info..
AnsiString curr_used_path; // currently scaned directory
int antal_files=0,antal_folders=0; // total files / folders in scan area
long total_size=0; // total size of all files in scan area
RichEdit1->Lines->Clear(); // clear first TRichBox of lines
RichEdit2->Lines->Clear(); // clear second TRichBox of lines
int done; // done, no more files in directory
RichEdit2->Lines->Add( scan_this ); // add first search directory to second TRichEdit
while(lstUrls->Lines->Count>0) // You know this…
{
curr_used_path = RichEdit2->Lines->Strings[0]; // set curr_used_path to the first line in second TRichEdit
done = findfirst((AnsiString(curr_used_path)+"*.*").c_str(), &ffblk,FA_DIREC|FA_HIDDEN|FA_RDONLY); // find first file / folder (all)
while(!done) // while something is found
{
int direct = strcmp(ffblk.ff_name, "."); // exclude dir with name '.'
int subdirect = strcmp(ffblk.ff_name, ".."); // exclude dir with name '..'
if(direct != 0 && subdirect != 0) // if dir is not above
{
if( (ffblk.ff_attrib&FA_DIREC) == FA_DIREC ) // if found is dir.
{
antal_folders++; // count of folders foud
RichEdit2->Lines->Insert( 1, curr_used_path + ffblk.ff_name+"\\" ); // add folder path to second TRichEdit
}
else // if found not is a folder (is file)
{
RichEdit1->Lines->Add( ";"+curr_used_path + ffblk.ff_name+"?"+IntToStr(ffblk.ff_fsize) ); // add file path+name+size to first TRichEdit
total_size += ffblk.ff_fsize; // No. of size of found files
antal_files++; // No. of found files
}
}
done = findnext( &ffblk ); // find next file / folder
}
RichEdit2->Lines->Delete( 0 ); // delete first line in second TRichEdit (the path we recently searched)
}
RichEdit1->Lines->SaveToFile( "C:\\test.txt" ); // save first TRichEdit lines to a file
}
Thanks for any idea…
Martin G Broman
mgb_svea@thevortex.com
DWS - Alpha Whitin Dead Wolf Society