0

eWAMパスtFileNameが有効かどうかを確認する方法は何ですか? してみCHDIRましたが手続きですが、返す関数はないのBooleanでしょうか?

4

2 に答える 2

0

以前の回答は機能します。ありがとうございます。ファイルとディレクトリの両方を検証するためのオプションがいくつかあります。

 ;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 
于 2015-10-23T21:29:56.387 に答える
0

2つの可能性が見えます。

  1. F_OPEN を使用してファイルを開こうとします (何も見つからない場合は 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)
    
于 2015-10-22T14:38:05.657 に答える