Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannt automaticly search hidden windows folders

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Hey all!! Could some one help me with this one??
The code below will search a folder including subdirectories, and it works the CD’s I’ve tested.
The code works perfectly on a CD (first intentionally to search, but my brother wanted me to enable hard drive search as well), but when I search my hard drive it seams to leave out some files and folders. (Note that I am running Windows Millennium Swedish version) I found out that the program tends to believe some folders are files(?). Followed are some folders listed with their attributes (could the attribs cause this problem? And if so, how do I solve it without changing them?).
‘C:\_restore’ [Hidden] (this one alone holds 5617 files in 5 folders ‘Win inf.’)
’C:\windows\pif\’ [Hidden]
’C:\windows\inf’ [Hidden]
’C:\windows\fonts’ [None]
’C:\windows\web’ [None]
’C:\windows\Cookies’[None]
’C:\windows\Sysbackup’ [Hidden]
’C:\windows\Applog’ [Hidden]

I have a total of 31318 files and 1573 folders (windows information) on my hard drive, but my program only reports 19131 files in 1342 folders!

// Needed for this code is a TButton(or other), TListBox, TRichEdit
void __fastcall Tform1::Button1Click(TObject *Sender)
AnsiString curr_path; // current search path
ListBox1->Items->Add("C:"); // start path to search from
while(ListBox1->Items->Count>0) // do while a path exists in ListBox1
{
curr_path = ListBox1->Items->Strings[0]+"\\"; // Change curr_path to first path-string in ListBox1
done = findfirst((AnsiString(curr_path)+"*.*").c_str(), &ffblk,faDirectory);
while (!done)
{
int direct = strcmp(ffblk.ff_name, ".");
int subdirect = strcmp(ffblk.ff_name, "..");
if(direct != 0 && subdirect != 0 && ffblk.ff_attrib==FA_DIREC) // make sure the 'name' is a folder
ListBox1->Items->Insert(1, curr_path + ffblk.ff_name ); // add path to ListBox
else if(direct != 0 && subdirect != 0 && ffblk.ff_attrib!=FA_DIREC) // make sure the 'name' isn't a folder
RichEdit1->Lines->Add( curr_path+ffblk.ff_name); // add filename to RichEdit1, incl. fullpath
done = findnext(&ffblk); // find next file
}
ListBox1->Items->Delete(0); // delete currently serached path from ListBox1
}
}

Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society
 
If you OR FA_DIREC and FA_HIDDEN you can find hidden directories. This will require you to change your program some so that you can find both regular directories and hidden directories. FYI, the attributes that findfirst and findnext use are:
Code:
FA_RDONLY	Read-only attribute
FA_HIDDEN	Hidden file
FA_SYSTEM	System file
FA_LABEL	Volume label
FA_DIREC	Directory
FA_ARCH 	Archive

A combination of constants can be ORed together.
[code]
 James P. Cottingham
[URL unfurl="true"]www.ivcusa.com[/URL]
 
I tried to modify the code slightly, though uncertain if I did it correct, gave a slightly different output!
[tt]while(ListBox1->Items->Count>0)
{
curr_path = ListBox1->Items->Strings[0]+"\\";
done = findfirst((AnsiString(curr_path)+"*.*").c_str(), &ffblk,faDirectory);
while (!done)
{
int direct = strcmp(ffblk.ff_name, ".");
int subdirect = strcmp(ffblk.ff_name, "..");
if( direct != 0 && subdirect != 0 && ffblk.ff_attrib==FA_DIREC|FA_HIDDEN) // here is the alteration FA_DIREC|FA_HIDDEN
ListBox1->Items->Insert(1, (AnsiString(curr_path) + AnsiString(ffblk.ff_name)) );
if( direct != 0 && subdirect != 0 && ffblk.ff_attrib!=FA_DIREC)
lstContents->Lines->Add( curr_path+ffblk.ff_name);
done = findnext(&ffblk);
}
ListBox1->Items->Delete(0);
}
[/tt]

This code will count a total of, 8384 files in 8620 folders; this only in the windows directory(windows counts, a total of 8455 files in 277 folders). It will add files to Listbox1 (should contains folder path only)
Come on someone out there!!! WHAT IS WRONG!! I have tried so many different codes that my brain is melting!!!

So sick and tired of all these crazy ways of writing codes

Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top