Home » U++ Library support » U++ Core » FindFile problem in XP [BUG?]
FindFile problem in XP [BUG?] [message #19422] |
Tue, 02 December 2008 22:38  |
 |
koldo
Messages: 3435 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
Here it is a possible problem when using FindFile in XP.
A small sample code:
CONSOLE_APP_MAIN
{
FindFile ff;
if(ff.Search("c:\\*.for")) {
do {
puts(Format("Found file: %s", ff.GetName()));
} while(ff.Next());
}
puts("Programa ended");
getchar();
}
If file list in c:\ is:
- RightFile.for
- WrongFile.fordoc
- WrongFile2.fordoc
Result is:
Found file: RightFile.for
Programa ended
But if file list in c:\ is:
- WrongFile.fordoc
- WrongFile2.fordoc
- zRightFile.for
The result is:
Found file: WrongFile.fordoc
Found file: zRightFile.for
Programa ended
It seems that the implementation of FindFile::Search() is ok but
handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w); does not work right, perhaps because it does not handle properly files with long extensions.
Best regards
Koldo
Best regards
Iñaki
|
|
|
Re: FindFile problem in XP [BUG?] [message #19423 is a reply to message #19422] |
Tue, 02 December 2008 23:05   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Tue, 02 December 2008 16:38 | Hello all
Here it is a possible problem when using FindFile in XP.
A small sample code:
CONSOLE_APP_MAIN
{
FindFile ff;
if(ff.Search("c:\\*.for")) {
do {
puts(Format("Found file: %s", ff.GetName()));
} while(ff.Next());
}
puts("Programa ended");
getchar();
}
If file list in c:\ is:
- RightFile.for
- WrongFile.fordoc
- WrongFile2.fordoc
Result is:
Found file: RightFile.for
Programa ended
But if file list in c:\ is:
- WrongFile.fordoc
- WrongFile2.fordoc
- zRightFile.for
The result is:
Found file: WrongFile.fordoc
Found file: zRightFile.for
Programa ended
It seems that the implementation of FindFile::Search() is ok but
handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w); does not work right, perhaps because it does not handle properly files with long extensions.
Best regards
Koldo
|
Funny, I have noticed this win32 bug a couple months ago, but my fix (which added more detailed pattern matching) was incomplete - I forget to check for the first file.
This should do it:
bool FindFile::Search(const char *name) {
pattern = GetFileName(name);
Close();
if(w)
handle = UnicodeWin32().FindFirstFileW(ToSystemCharsetW(name), w);
else
handle = FindFirstFile(ToSystemCharset(name), a);
if(handle == INVALID_HANDLE_VALUE)
return false;
if(!PatternMatch(pattern, GetName()))
return Next();
return true;
}
Mirek
|
|
|
|
Goto Forum:
Current Time: Mon May 12 15:17:09 CEST 2025
Total time taken to generate the page: 0.02559 seconds
|