[CreateDirectory]Return error code for failure.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

[CreateDirectory]Return error code for failure.

Post by skywalk »

Because FileSize() returns false positives if rejected characters in pathname,
it falls back to CreateDirectory() or api call to SHCreateDirectory_() to know for certain if a path exists?
Or since FileSize() returns codes, maybe a new error code can be created?

EDIT: PathFileExists_(Fpathname$) does not return false positives if wildcard characters in Fpathname$.
Last edited by skywalk on Mon Mar 26, 2018 8:46 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: [CreateDirectory]Return error code for failure.

Post by Marc56us »

Another (secure) way, check filename before check size or exist

CheckFilename()
Returns nonzero if the filename does not contain invalid characters and zero if it does.

Code: Select all

Debug CheckFilename("c:\try3\z|z")             
Debug CheckFilename("c:\try3\z:z")             
Debug CheckFilename("c:\try3\z"+#DQUOTE$+"z")  
Debug CheckFilename("c:\try3\z<z")             
Debug CheckFilename("c:\try3\z>z")             
Debug CheckFilename("c:\try3\z*z")             
Debug CheckFilename("c:\try3\z?z")     

Code: Select all

0
0
0
0
0
0
0
= bad filename for all

But you're right, actually, it would be nice if FileSize automatically tests if the file name is valid before continuing.

:wink:
Post Reply