验证文件路径在 eWAM 中是合法的

Validating a file path is legal in eWAM

eWAM 中检查路径 tFileName 是否有效的方法是什么? 我试了CHDIR,不过是程序,难道没有returnsBoolean的函数吗?

我看到两种可能性。

  1. 使用 F_OPEN 尝试打开文件(returns 0 如果没有找到,> 0 否则)。如果 > 0,请不要忘记关闭句柄。

    var hFile : Int4
    
    hFile = wUtil.F_OPEN(64, 'D:\DummyFile.txt')
    if hFile > 0
        wUtil.F_CLOSE(hFile)
    endIf
    
  2. 在模块中定义一个外部,包装到PathFileExists

    function PathFileExists(pszPath : Pointer) return Boolean external 'Shlwapi.PathFileExistsA'
    

    并使用它:

    var res : Boolean
    var path : CString
    
    path = 'D:\Path\File.ext'
    res = YourModule.PathFileExists(@path)
    

之前的答案有效,谢谢你。这里有更多选项,用于验证文件和目录。

 ;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