[v562] FileSize("c:\x\BadCharacterInPath") = False Positive

Post bugreports for the Windows version here
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

[v562] FileSize("c:\x\BadCharacterInPath") = False Positive

Post by skywalk »

EDIT: PathFileExists_(Fpathname$) does not return false positives if wildcard characters in Fpathname$.
Maybe PB FileSize() can use this function for Windows?

Code: Select all

; Create temp directory "c:\try3\z_z"
CreateDirectory("c:\try3")
CreateDirectory("c:\try3\z_z")
Debug "-- FileSize --"
Debug FileSize("c:\try3\z|z")             ; -1
Debug FileSize("c:\try3\z:z")             ; -1
Debug FileSize("c:\try3\z"+#DQUOTE$+"z")  ; -1
Debug FileSize("c:\try3\z<z")             ;BUG! -2
Debug FileSize("c:\try3\z>z")             ;BUG! -2
Debug FileSize("c:\try3\z*z")             ;BUG! -2
Debug FileSize("c:\try3\z?z")             ;BUG! -2
Debug "-- SetCurrentDirectory --"
Debug SetCurrentDirectory("c:\try3\z_z")  ; 1
Debug SetCurrentDirectory("c:\try3\z|z")  ; 0
Debug SetCurrentDirectory("c:\try3\z:z")  ; 0
Debug SetCurrentDirectory("c:\try3\z"+#DQUOTE$+"z") ; 0
Debug SetCurrentDirectory("c:\try3\z<z")  ; 0
Debug SetCurrentDirectory("c:\try3\z>z")  ; 0
Debug SetCurrentDirectory("c:\try3\z*z")  ; 0
Debug SetCurrentDirectory("c:\try3\z?z")  ; 0
Last edited by skywalk on Mon Mar 26, 2018 8:48 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [v562] FileSize("c:\x\BadCharacterInPath") = False Posit

Post by kenmo »

Code: Select all

Debug FileSize("c:\try3\z*z")             ;BUG! -2
Debug FileSize("c:\try3\z?z")             ;BUG! -2
These match z_z because the Windows filesize function supports * and ? wildcards.

Code: Select all

Debug FileSize("c:\try3\z<z")             ;BUG! -2
Debug FileSize("c:\try3\z>z")             ;BUG! -2
These I don't know understand...
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [v562] FileSize("c:\x\BadCharacterInPath") = False Posit

Post by skywalk »

Whoa, I did not consider the wildcard characters :idea:
How would Windows use '<', '>'?
I'll make a feature request for CreateDirectory() to return more than 0 or 1.
I need to know if it fails for "Directory Exists" or "Bad Character in Path Name"?
Since, now I have to use the api = SHCreateDirectory_(#Null, DirPath$).
It returns the correct state for all rejected characters in the path:
; / \ : * ? " < > |
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: [v562] FileSize("c:\x\BadCharacterInPath") = False Posit

Post by cas »

https://blogs.msdn.microsoft.com/jeremykuhne/2017/06/04/wildcards-in-windows/ wrote:...there are actually five wildcards in Windows:

Wildcard Meaning
* Zero or more characters.
? Exactly one character.
< Matches zero or more characters until encountering and matching the final period in the name. (DOS_STAR)
> Matches any single character, or zero if to the left of a period or the end of the string- or contiguous to other > that are in said position. (DOS_QM)
" Matches a period or zero characters at the end of the string. (DOS_DOT)

...Win32 implicitly changes your wildcards. ...The rules are as follows:

All '?' are changed to '>'.
All '.' followed by '?' or '*' are changed to '"'.
A path ending in '*' that had a final period before normalizing is changed to '<'.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [v562] FileSize("c:\x\BadCharacterInPath") = False Posit

Post by kenmo »

Code: Select all

Debug CheckFilename("z_z")
Debug CheckFilename("z*z")
Debug CheckFilename("z?z")
Debug CheckFilename("z>z")
Debug CheckFilename("z<z")
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: [v562] FileSize("c:\x\BadCharacterInPath") = False Posit

Post by skywalk »

Windows only PathFileExists_() works for all cases. :idea:

Code: Select all

Macro FileExistsW(Fpathname)
  PathFileExists_(Fpathname)
EndMacro
Macro FileExists(Fname)
  ;BUG; v562, FileSize() = -2 for existing path queried with a bad char?
  ;           Allows wildcards in its search: ?,*, including '<','>'.
  ;  0 = File or Folder does not exist
  ;  1 = File Exists
  ; -1 = Folder Exists
  ; Since FileSize() returns:
  ;       -1 = File Not found.
  ;       -2 = File is a directory.
  ;        0 = Empty File, > 1 = File Exists
  ;        FileSize() respects '*' wildcards and reports results accordingly.
  (FileSize(Fname) + 1)
EndMacro
; Create temp directory "c:\try3\z_z"
CreateDirectory("c:\try3")
CreateDirectory("c:\try3\z_z")
; Create dummy files in temp directory "c:\try3\z_z"
CreateFile(0,"c:\try3\z_z\1_2.txt") : CloseFile(0)
CreateFile(1,"c:\try3\z_z\1%2.txt") : CloseFile(1)
Debug "-- FileExists(paths) --"
Debug "FileExists('c:\try3\z_z')  = " + Str(FileExists("c:\try3\z_z"))
Debug "FileExists('c:\try3\z|z')  = " + Str(FileExists("c:\try3\z|z"))
Debug "FileExists('c:\try3\z:z')  = " + Str(FileExists("c:\try3\z:z"))
Debug "FileExists('c:\try3\z'z')  = " + Str(FileExists("c:\try3\z"+#DQUOTE$+"z"))
Debug "FileExists('c:\try3\z<z')  = " + Str(FileExists("c:\try3\z<z"))
Debug "FileExists('c:\try3\z>z')  = " + Str(FileExists("c:\try3\z>z"))
Debug "FileExists('c:\try3\z*z')  = " + Str(FileExists("c:\try3\z*z"))
Debug "FileExists('c:\try3\z?z')  = " + Str(FileExists("c:\try3\z?z"))
Debug "-- FileExistsW(paths) --"
Debug "FileExistsW('c:\try3\z_z') = " + FileExistsW("c:\try3\z_z")
Debug "FileExistsW('c:\try3\z|z') = " + FileExistsW("c:\try3\z|z")
Debug "FileExistsW('c:\try3\z:z') = " + FileExistsW("c:\try3\z:z")
Debug "FileExistsW('c:\try3\z'z') = " + FileExistsW("c:\try3\z"+#DQUOTE$+"z")
Debug "FileExistsW('c:\try3\z<z') = " + FileExistsW("c:\try3\z<z")
Debug "FileExistsW('c:\try3\z>z') = " + FileExistsW("c:\try3\z>z")
Debug "FileExistsW('c:\try3\z*z') = " + FileExistsW("c:\try3\z*z")
Debug "FileExistsW('c:\try3\z?z') = " + FileExistsW("c:\try3\z?z")
Debug "-- FileExists(files) --"
Debug "FileExists('c:\try3\z_z\1_2.txt')  = " + Str(FileExists("c:\try3\z_z\1_2.txt"))
Debug "FileExists('c:\try3\z_z\1%2.txt')  = " + Str(FileExists("c:\try3\z_z\1%2.txt"))
Debug "FileExists('c:\try3\z_z\1?2.txt')  = " + Str(FileExists("c:\try3\z_z\1?2.txt"))
Debug "FileExists('c:\try3\z_z\1*2.txt')  = " + Str(FileExists("c:\try3\z_z\1*2.txt"))
Debug "-- FileExistsW(files) --"
Debug "FileExistsW('c:\try3\z_z\1_2.txt') = " + FileExistsW("c:\try3\z_z\1_2.txt")
Debug "FileExistsW('c:\try3\z_z\1%2.txt') = " + FileExistsW("c:\try3\z_z\1%2.txt")
Debug "FileExistsW('c:\try3\z_z\1?2.txt') = " + FileExistsW("c:\try3\z_z\1?2.txt")
Debug "FileExistsW('c:\try3\z_z\1*2.txt') = " + FileExistsW("c:\try3\z_z\1*2.txt")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply