eWAM
检查路径tFileName
是否有效的方法是什么?我试过CHDIR
了,但是它是一个过程,没有返回的函数Boolean
吗?
问问题
86 次
2 回答
0
我看到了两种可能性。
使用 F_OPEN 尝试打开文件(如果没有找到则返回 0,否则返回 > 0)。如果它> 0,请不要忘记关闭句柄。
var hFile : Int4 hFile = wUtil.F_OPEN(64, 'D:\DummyFile.txt') if hFile > 0 wUtil.F_CLOSE(hFile) endIf
在模块中定义一个外部,包装到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 回答
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 回答