Page 1 of 1

CheckFullFilename()

Posted: Fri Feb 18, 2011 10:46 am
by c4s
We have CheckFilename() for the name of the file but what about something like CheckPath() (with optional parameter for checking the hard disk letter or not) that validates the path and CheckFullFilename() that checks the complete filename for not allowed characters.

Re: CheckFullFilename()

Posted: Fri Feb 18, 2011 5:51 pm
by cas
It is easy to make one by yourself by combining FindString(), StringField() and CheckFilename().

Re: CheckFullFilename()

Posted: Fri Feb 18, 2011 6:21 pm
by skywalk
Or a FileSize() Macro... :idea:

Code: Select all

Macro FileExists(Fname)
  ;  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  

Define.i fn
CreateDirectory("c:\z~z\")
fn=CreateFile(0,"c:\z~z\1.txt"): CloseFile(0)
fn=CreateFile(0,"c:\z~z\2.txt"): CloseFile(0)

Debug " - File(s) or Folder Exists? - "
Debug FileExists("c:\zz~z\")      ;  0 = Not a Folder 
Debug FileExists("c:\z~z\*.*")    ; -1 = Valid Folder
Debug FileExists("c:\z~z\*.txt")  ;  1 = Valid File(s)
Debug FileExists("c:\z~z\1.txt")  ;  1 = Valid File
Debug FileExists("c:\z~z\3.txt")  ;  0 = Not a File
Debug FileExists("c:\z~z\*.csv")  ;  0 = File(s) Not Found
Debug FileExists("c:\z~z\?,3")    ;  0 = File Not Found
;DeleteDirectory("c:\z~z\", "*.*", #PB_FileSystem_Recursive)