|
__makaveli__ wrote:
I have tried making a recursive method using FindFirstFile and FindNextFile but don't seem to be having any luck.
Show us the code that is not working.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
void SearchFolders(LPCTSTR wStart)
{
WIN32_FIND_DATA hDat;
HANDLE hFindFile;
hFindFile = FindFirstFile(wStart, &hDat);
if( hFindFile != INVALID_HANDLE_VALUE ) {
while( FindNextFile(hFindFile, &hDat) )
{
if( hDat.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY ) {
// File is a folder
SearchFolders(hDat.cFileName);
} else {
// File is a file
MessageBox(0, hDat.cFileName, "File", MB_OK);
}
}
}
}
I have deleted the code that crashes but this was my last attempt, I tried to make it as simple as possible so I could expand on it once I got it showing a messagebox for each file but I do not get one messagebox.
|
|
|
|
|
Try changing
if( hDat.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY ) {
to
if( hDat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks for the suggestion but still no messageboxes
|
|
|
|
|
Dont forget the wildcards:
SearchFolders("D:\\test\\*.*");
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I have just tried that, I am getting somewhere now, at first I got a stack of messageboxes all saying ".\*", I have now added a check for dots but it's still not recursive.
I'm now using:
void SearchFolders(LPCTSTR wStart)
{
WIN32_FIND_DATA hDat;
HANDLE hFindFile;
char DirSpec[MAX_PATH];
ZeroMemory(DirSpec, MAX_PATH);
strncpy (DirSpec, wStart, strlen(wStart+1));
strncat (DirSpec, "\\*", 3);
hFindFile = FindFirstFile(DirSpec, &hDat);
if( hFindFile != INVALID_HANDLE_VALUE ) {
while( FindNextFile(hFindFile, &hDat) )
{
if( hDat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
// File is a folder
if( (strncmp(hDat.cFileName, ".", 1) != 0) || (strncmp(hDat.cFileName, "..", 2) != 0 ) ) {
char subDir[MAX_PATH];
strcat(subDir, hDat.cFileName);
strcat(subDir, "\\*");
SearchFolders(subDir);
}
} else {
// File is a file
MessageBox(0, hDat.cFileName, "File", MB_OK);
}
}
}
}
|
|
|
|
|
__makaveli__ wrote:
strncat(DirSpec, "\\*", 3);
strncat(DirSpec, "\\*.*", 4); __makaveli__ wrote:
if( (strncmp(hDat.cFileName, ".", 1) != 0) || (strncmp(hDat.cFileName, "..", 2) != 0 ) ) {
char subDir[MAX_PATH];
strcat(subDir, hDat.cFileName);
strcat(subDir, "\\*");
SearchFolders(subDir);
The second condition is redundant (at least I've not ever seen a folder whose name began with a '.' but whose second character was not a '.'). Also, appending '*' here and at the start of the function is wrong.
if (hDat.cFileName[0] != '.')
{
char subDir[MAX_PATH];
strcpy(subDir, wStart);
strcat(subDir, "\\");
strcat(subDir, hDat.cFileName);
SearchFolders(subDir);
} See here and here for others' interpretation of this exercise. Here is an MFC snippet.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
DavidCrow wrote:
The second condition is redundant (at least I've not ever seen a folder whose name began with a '.' but whose second character was not a '.').
I have. The last time I used the CFile class from MFC, these names came up when I search through some folders...
Also when you use the dir command in dos, you see those names for the current and previous directory!
I also got the blogging virus..[^]
|
|
|
|
|
Bob Stanneveld wrote:
Also when you use the dir command in dos, you see those names for the current and previous directory!
That's exactly what I said. Unless a folder was named something like ".abc" I do not see the need to check the second character if the first one was a dot. It certainly does not hurt anything to check, but I was just trying to shorten the OP's code down a bit.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
__makaveli__ wrote:
SearchFolders(hDat.cFileName);
You'll need to append the previous directories to this path, and then call SearchFolders, or change your working directory before and after the call. The problem is that FindFirstFile is *always* searching the current directory.
|
|
|
|
|
Along with what everyone else is stating two more changes to your code.
First, the API FindFirstFile populates hDat you should use a do{}while(); loop instead of a while{} loop.
do
{
...
}while(FindNextFile(hFindFile, &hDat));
FindClose(hFindFile);
The reason you should process hDat before you call FindNextFile is because if you have a wildcard search like ABC*.* you will lose the first (and possibly the only) match.
Second, as noted in my code snippet, don't forget to close each findfile handle.
Kelly Herald
Software Developer
MPC
|
|
|
|
|
Can you show the main loop
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Try giving a bigger timeout
and why dont you try pcap_live_dump
Check in the developper pack the sample kdump and pktdump_ex
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Does it make sence to use WaitForSingleObject for UI thread. What I found if I call
WaitForSingleObject(m_hUIThread, INFINITE) where m_hUIThread is handle to thread object type CWinThread my call will stuck for ever. I check thread status is always waiting for user request. Which means in most of cases GetMessage() in CWinThread resulting this status. I just want to know is this true?
Thanks,
Alex.
|
|
|
|
|
You need to use MsgWaitForSingleObject and if you get a windows message, you need to pump it through the UI thread's message handler. Use the result of MsgWaitForSingleObject call to determine if the action returning is failed, timeout, message, or event was triggered. Some synchronization objects also return abandoned.
|
|
|
|
|
|
am remodeling the code in my project.
I had one class (lets say CClass1 ) who was inhereted from let's say CBaseClass .
Now I have to remodel this class into 2 classes CClass3 & CClass2 . Both are inherited from CBaseClass (which is a base class for many other classes too)
The problem is in MEMBERS which are now half in CClass3 and half in CClass2 . And I need a way for them to comunicate.
So I tried to solve this using STATIC members in new class CBaseClass2 which I derived from CBaseClass and then I derived CClass2 & CClass3 from this class( CBaseClass2 ).
But i have errors:
error LNK2001: unresolved external symbol "public: static int CBaseClass2::sta_member1" (?sta_member1@CClass2@@2HA)
Any ideas to this question. I think this must be known to a lot of people.
Thanks in advance
|
|
|
|
|
If it won't break any already existing code, why not put all the shared variables in CBaseClass? If you're trying to declare them as static in a middle class, did you actually initialize them in the header file below the class definition? If not, that's probably why you got the errors.
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
can you please give me an example. 'couse I most defenitly didn't do this.
Love is the law, love under will.
|
|
|
|
|
|
tnx. But i think the errors are becouse of this:
Functions declared with the static modifier by definition have file scope. Static variables have the same limitation. Trying to access any static variables from outside of the file in which they are declared can result in a compile error or LNK2001.
(from MSDE)
Love is the law, love under will.
|
|
|
|
|
but if you declare it within the class definition, you just have to intialize it outside of the class definition in the same header file. as long as the class is included, you should be able to reference it as CMyClass::m_nCounter anywhere the header file is included.
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Since the variables are common to both CClass3 and CClass2 , shouldn't they therefore belong in CBaseClass ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
why dont you create an another struct or class(say 'info' class) that has these members that u need to pass from one class to the other,then create objects of this info class in both ur classes,then make a member function in ur class2 and/or class3,which acceptz thiz info object as a function parameter.
hope thiz helpz!
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
one thing u can do is create a friend function which is common to both the classes then u can do inter communications using ur friend function which'll act as bridge between to classes.
if ur not able to do it by ur-self ask me
|
|
|
|