FileSize() bug or feature ?

Just starting out? Need help? Post your questions and find answers here.
Phlos
User
User
Posts: 85
Joined: Fri May 16, 2003 7:17 pm

FileSize() bug or feature ?

Post by Phlos »

Hello all,

Look at this simple line of code :

Code: Select all

Debug Hex(FileSize("*.jpg"))
If you run it in a directory where it resides some "jpg" picture, it will not returns "-1" error code (file not found), but the size a jpg. :shock: :shock:
Since when the parameter of FileSize() is not a filepath but more like a "mask" with wildcard allowed ? :shock:

Nothing about that on documentation.
Until now, I trusted FileSize() to know if a file exists or not (with -1 error code), but no I can't, even if the file "*.jpg" doesn't exist, it does not return -1. :oops:
Last edited by Phlos on Sat May 19, 2012 2:10 pm, edited 1 time in total.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: FileSize() bug or feature ?

Post by Shield »

I think the problem might be related to a direct call to the Windows function FindFirstFile
which accepts wildcards. I'd say this should be called a bug as the behavior is clearly
not what the function is intended to do.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Phlos
User
User
Posts: 85
Joined: Fri May 16, 2003 7:17 pm

Re: FileSize() bug or feature ?

Post by Phlos »

Yes you are right, it calls FindFirstFile(). But it should not. That's not a reliable behaviour. :cry:
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: FileSize() bug or feature ?

Post by skywalk »

Not a bug, just lack of documentation.
Discussed last year and I find it very useful...
viewtopic.php?p=347080&sid=076dacc1eb72 ... d4#p347080
http://www.purebasic.fr/english/viewtop ... 87#p347087
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Fred
Administrator
Administrator
Posts: 16688
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FileSize() bug or feature ?

Post by Fred »

Looks like a bug to me
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: FileSize() bug or feature ?

Post by Dude »

Fred wrote:Looks like a bug to me
So... can it get fixed? I just tested it:

Code: Select all

Debug FileSize("D:\*.jpg") ; Returns 155009
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: FileSize() bug or feature ?

Post by Josh »

Phlos wrote:Until now, I trusted FileSize() to know if a file exists or not ...
For an alternative FileExist() look here.
sorry for my bad english
Post Reply