|
|
楼主 |
发表于 2015-9-7 07:24:48
|
显示全部楼层
本帖最后由 bhffhzh 于 2015-9-7 13:32 编辑
我用一个另类的方法让大家知道我的想法吧。
大家运行就知道了,当然这种方法实在不可取。
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("Form1", 623, 442, 192, 124)
- $Input1 = GUICtrlCreateInput("c:", 80, 176, 297, 21)
- $Button1 = GUICtrlCreateButton("Button1", 336, 280, 89, 49)
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
-
- Exit
- EndSwitch
- $Search11 = GUICtrlRead($Input1)
- $hzh = StringMid($Search11, 1, 3) ;提取路径的前三个字符
- $iFileExists1 = FileExists($hzh) ;检查文件或目录是否存在,这里其实是检查诸如是否存在c:盘 d:盘之类的。
- If $iFileExists1 = 0 Or _PathValidateCheck1($Search11, 1) = 0 Or StringRegExp($Search11, "[^\x00-\xff]") Then ;盘符不对,路径含中文,不符合Windows文件命名规则 均不执行。
- GUICtrlSetState($Button1, $GUI_DISABLE)
- MsgBox(0,0,"不合法")
- Else
- GUICtrlSetState($Button1, $GUI_ENABLE)
- MsgBox(0,0,"合法")
- EndIf
- Sleep(500)
- WEnd
- ;验证安装目录路径
- Func _PathValidateCheck1($Search11, $OnlyAbsolutePath = 0)
- ;afan提示:验证路径是否合法(路径可不存在)。
- ; 本函数可用于验证用户提供的路径是否合法有效。
- ; 与 FileExists 用途不同,FileExists 验证的路径必须存在,而本函数路径可不存在,只要符合Windows文件命名规则即可。
- ;$sPath - 待验证的路径字符串
- ;$OnlyAbsolutePath - 仅验证绝对路径
- ;返回值 - 合法返回1;非法返回0,并设置@Error非0。
- If $OnlyAbsolutePath And Not StringRegExp($Search11, '^[a-zA-Z]:') Then Return SetError(1, 0, 0)
- Local $aSR1 = StringRegExp($Search11, '^(.*?)([^\\/]+)\\?
- , 1)
- If @error Then Return SetError(2, 0, 0)
- If StringLen($aSR1[0]) >= 248 Or StringLen($aSR1[1]) >= 260 Then Return SetError(2, 0, 0)
- If StringRegExp($Search11, '[[:cntrl:]]') Then Return SetError(3, 0, 0)
- Local $sIns = '?'
- If $OnlyAbsolutePath Then $sIns = ''
- If StringRegExp($Search11, '^(?:[a-zA-Z]:\\?|([a-zA-Z]:\\)' & $sIns & '(\S[^\\/:*?"<>|]*(?<!\s)\\)*\S[^\\/:*?"<>|]*(?<!\s)\\?)
- ) Then Return 1
- Return SetError(4, 0, 0)
- EndFunc ;==>_PathValidateCheck1
复制代码 |
|