FileSize() with a wild card?
Posted: Wed Feb 16, 2011 5:52 pm
Removed due to inaccurate information.
http://www.purebasic.com
https://www.purebasic.fr/english/
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" ?
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.
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...
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?
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 ..."
...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
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
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