Search code examples
file-handlingewam

Validating a file path is legal in eWAM


What is the method in eWAM which will check if a path tFileName is valid? I tried CHDIR, however it is a procedure, is there not a function that returns Boolean?


Solution

  • Previous answer works, thank you for that. Here are some more options, for both validating a file and a directory.

     ;Validate the that a directory exists at that path.
     function ValidateFileDirectory(path : CString) return Boolean    
       uses wUtil
    
       var testPath : CString
    
    ;Given the path to a directory,it will return True if that directory exists.
    ;-Test if the path is valid before you write a file.
       testPath = wUtil.FGETDIR(path)
       if testPath = path
          _Result = True
       else
          _Result = False
          Alert(kw_BadPath)
          ;! it will return false if you give it a path to a file, even if the file exists.
       endIf
    endFunc 
    
    ;Validate that the file exists there.
    function ValidateFileExists(path : CString) return Boolean
       uses wUtil
    
       ;Given the path to a file, returns True if it finds the File.
       ;-test to make sure a file is there before you read,
       ;-test if a file was written.
       if wUtil.FGETNAME(path) <> ''
          _Result = True
       else
          Alert(kw_FileNotFound)
          _Result = False
       endIf
    endFunc 
    
    function TestOpenFile(path : CString) return Int4
       uses wUtil
    
       ;Returns 0 if it doesn't find a file, otherwise it returns a larger int4.  
       _Result = wUtil.T_OPEN(path)
       wUtil.T_CLOSE(_Result)
    endFunc