请问怎么有效的检查一个路径是否正确
我自己这样检查感觉很不到位;希望各位给点好些的方法;能够检查全面一些#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Group1 = GUICtrlCreateGroup("SelectDirectory", 16, 96, 577, 89)
$Input1 = GUICtrlCreateInput("", 24, 136, 481, 21)
$Button1 = GUICtrlCreateButton("...", 512, 136, 75, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button2 = GUICtrlCreateButton("确定", 520, 208, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input1,FileSelectFolder("",""))
Case $Button2
Local $path = GUICtrlRead($Input1)
If $path = "" Then
MsgBox(0,"提示","目录不能为空。")
ElseIf StringMid($path,2,2) <> ":\" Then
MsgBox(0,"提示","路径错误。")
Else
MsgBox(0,"","路径是正确的")
EndIf
EndSwitch
WEnd
这样当第一个字符不为英文字母也是正确;因为我只检查了第二和第三个是否等于 :\,各位还有什么更好的方法吗?谢谢 FileExists ? #Include <WinAPIEx.au3>
_WinAPI_PathIsUNC 或者参考下http://www.autoitx.com/thread-43473-1-1.html Local $a
$a = '路径名不合法'
$a= '路径名合法'
$str = @ScriptFullPath & " >> " & $a & @CRLF ; File.
$str &= """C:"" >> " & $a & @CRLF ; Drive.
$str &= "C: >> " & $a & @CRLF ; Drive.
$str &= @ProgramFilesDir & " >> " & $a & @CRLF ; Directory.
$str &= """Z:File.txt"" >> " & $a & @CRLF ; Shouldn't exist!
$str &= "D:bank >> " & $a & @CRLF
$str &= "L: >> " & $a & @CRLF ;全/半角
MsgBox(0, '_WinAPI_PathFileExists', $str)
Func _WinAPI_PathFileExists($sFilePath)
Local $aReturn = DllCall('shlwapi.dll', 'int', 'PathFileExistsW', 'wstr', $sFilePath)
If @error Then
Return SetError(1, 0, 0)
EndIf
Return $aReturn
EndFunc ;==>_WinAPI_PathFileExists
进来学习一下!!!!!!!!!!!!!!!1
页:
[1]