FileSize() with a wild card?
FileSize() with a wild card?
Removed due to inaccurate information.
Last edited by jassing on Fri Feb 18, 2011 7:43 am, edited 2 times in total.
Re: FileSize() with a wild card?
Seems to return the filesize of the first file that matches the wildcard pattern........
I don't know if this is considered a bug or not!
I don't know if this is considered a bug or not!
Re: FileSize() with a wild card?
Why would you think the filename cannot be specified with a wildcard?jassing wrote:Shouldn't FileSize() return -1 if the file is, for example, "c:\temp\*.jpg" ?
If you don't want a wildcard in the filename you should filter it out before using FileSize().
Re: FileSize() with a wild card?
Removed due to inaccurate information.
Last edited by jassing on Fri Feb 18, 2011 7:44 am, edited 1 time in total.
Re: FileSize() with a wild card?
I would say it's a bug because that behavior isn't stated in the help file:

Also my programs don't expect that behavior as I didn't know it until I read it here. Either the file exists or it doesn't. I seriously don't want to know what happens in any of my programs if the user uses something with "*" in a file string...Help file wrote:Returns the size of the specified file.

If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: FileSize() with a wild card?
CheckFilename() to the rescuec4s wrote:I seriously don't want to know what happens in any of my programs if the user uses something with "*" in a file string...

Re: FileSize() with a wild card?
Are you sure about that?jassing wrote:Nor is it returning the size of *ANY* file that matches the wildcard.. so what is it returning?
It seems to return the size in bytes of the first file (for me at least) in any folder, of any file type.
Make sure you check the exact size in bytes... for example I tested it on a file that was 8181990 bytes, but in Windows Explorer it rounds this to 7.80 MB.
Re: FileSize() with a wild card?
If the filename used with FileSize() contains a wildcard than the size of *ANY* file that matches will be returned, but only the first one. If no file matches then the value -1 will be returned.jassing wrote:So in my code -- what is filesize() reporting? It's not reporting the sum of the files. Nor is it returning the size of *ANY* file that matches the wildcard.. so what is it returning?
I guess I misread the help -- it says to use it for testing the existance of a file.
the file c:\temp\*.jpg does not exist.
There are files that match that, but no file of that name exists.
Since we can't use filesize() for testing if a file is there or not -- what is the best way to do that?
or is it a case of "roll your own ..."
When you say that it returns a value that doesn't match any file in the directory are the values being compared at a resolution of bytes? I ask because when byte values are converted to KB's for instance the value is frequently divided by 1024 and not 1000. If this is the case it can seem unequal when it is in fact equal.
When used to test for the existence of a file, any positive value returned indicates a file matching the filename exists. Again, if you don't want wildcards in the filename then filter them out first. If you are having a user enter the filename then validate it by removing the path and using CheckFilename() before passing it on to FileSize().
It's not a case of roll-your-own. Only you would know whether or not you would want to allow a user to enter a wildcard or not as part of a filename. Those things are hopefully determined in the planning stage but unfortunately crop up in the debug stage a lot.

Re: FileSize() with a wild card?
Removed due to inaccurate information.
Last edited by jassing on Fri Feb 18, 2011 7:43 am, edited 1 time in total.
Re: FileSize() with a wild card?
CheckFilename() checks a filename, not the whole path. In a path the characters : and \ are present, which are invalid in file names, thus the function returns 0.
Re: FileSize() with a wild card?
Filesize checks the size of the specified file. An asterisk is not specifying a file. No bug.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: FileSize() with a wild card?
Removed due to inaccurate information.
Last edited by jassing on Fri Feb 18, 2011 7:44 am, edited 1 time in total.
Re: FileSize() with a wild card?
...Also it's often a tip here for newbies:jassing wrote:The docs says to use it to check for the existence of a file... a file. So an invalid file should return -1PB wrote:Filesize checks the size of the specified file. An asterisk is not specifying a file. No bug.
Pseudo conversation wrote:A: How can I find out if a file exists?
B: Use FileSize() like this:A: Ah great, I really didn't know I could use this function for it...thanks.Code: Select all
Procedure FileExists(File.s) Protected Result If FileSize(File) >= 0 Result = #True Else Result = #False ; Doesn't exist or a folder EndIf ProcedureReturn Result EndProcedure
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Re: FileSize() with a wild card?
Hi, jAssing. If I may:
See also: http://www.techterms.com/definition/gigo
The manual for CheckFilename() says: The 'Filename$' must not include its path.jassing wrote:when I issue debug "checkfilename("C:\temp\snap6.jpg") it returns 0
Filenames do not have wildcards in them. Use a valid filename specification with FileSize().jassing wrote:The docs says to use it to check for the existence of a file... a file
See also: http://www.techterms.com/definition/gigo
Last edited by C64 on Fri Feb 18, 2011 1:01 pm, edited 1 time in total.
Re: FileSize() with a wild card?
Make a small change to your code:jassing wrote:Nah, because when I issue debug "checkfilename("C:\temp\snap6.jpg") it returns 0Arctic Fox wrote:CheckFilename() to the rescuec4s wrote:I seriously don't want to know what happens in any of my programs if the user uses something with "*" in a file string...
When I drop to dos and copy/paste the file name/path and do dir c:\temp\snap6.jpg it's there...
Code: Select all
#filename = "c:\temp\myfun.txt"
If CreateFile(0,#filename)
WriteString(0,"Fun")
CloseFile(0)
Debug "Checking filename: "+#filename
Debug CheckFilename( GetFilePart(#filename ) ) ; <== Exclude the path from the filename check
If CheckFilename( GetFilePart(#filename) )
Debug FileSize(#filename)
EndIf
Else
Debug "FAILED TO CREATE FILE"
EndIf