Page 1 of 1

FileSize() bug or feature ?

Posted: Sat May 19, 2012 1:39 pm
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:

Re: FileSize() bug or feature ?

Posted: Sat May 19, 2012 2:01 pm
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.

Re: FileSize() bug or feature ?

Posted: Sat May 19, 2012 2:11 pm
by Phlos
Yes you are right, it calls FindFirstFile(). But it should not. That's not a reliable behaviour. :cry:

Re: FileSize() bug or feature ?

Posted: Sat May 19, 2012 3:36 pm
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

Re: FileSize() bug or feature ?

Posted: Sat May 19, 2012 5:02 pm
by Fred
Looks like a bug to me

Re: FileSize() bug or feature ?

Posted: Sun Jan 14, 2018 4:23 am
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

Re: FileSize() bug or feature ?

Posted: Sun Jan 14, 2018 6:59 am
by Josh
Phlos wrote:Until now, I trusted FileSize() to know if a file exists or not ...
For an alternative FileExist() look here.