Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » FindFile problem in XP [BUG?]
FindFile problem in XP [BUG?] [message #19422] Tue, 02 December 2008 22:38 Go to next message
koldo is currently offline  koldo
Messages: 3358
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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
Re: FindFile problem in XP [BUG?] [message #19425 is a reply to message #19423] Wed, 03 December 2008 09:32 Go to previous message
koldo is currently offline  koldo
Messages: 3358
Registered: August 2008
Senior Veteran
That's it!

Best regards
Iñaki
Previous Topic: [BUG] resolving program's file name for debug output
Next Topic: String [FEATURE REQUEST]
Goto Forum:
  


Current Time: Mon Apr 29 13:19:59 CEST 2024

Total time taken to generate the page: 0.02895 seconds