找回密码
 加入
搜索
查看: 1977|回复: 5

[系统综合] 请问怎么有效的检查一个路径是否正确

[复制链接]
发表于 2014-1-15 20:16:21 | 显示全部楼层 |阅读模式
我自己这样检查感觉很不到位;希望各位给点好些的方法;能够检查全面一些
#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

这样当第一个字符不为英文字母也是正确;因为我只检查了第二和第三个是否等于 :\  ,各位还有什么更好的方法吗?谢谢
发表于 2014-1-15 21:31:44 | 显示全部楼层
FileExists ?
发表于 2014-1-25 16:28:43 | 显示全部楼层
#Include <WinAPIEx.au3>
_WinAPI_PathIsUNC
发表于 2014-2-9 15:10:25 | 显示全部楼层
发表于 2014-2-10 00:47:55 | 显示全部楼层
[au3]Local $a[3]
$a[1] = '路径名不合法'
$a[2]= '路径名合法'
$str = @ScriptFullPath & " >> " & $a[_WinAPI_PathFileExists(@ScriptFullPath)+1] & @CRLF ; File.
$str &= """C:"" >> " & $a[_WinAPI_PathFileExists("""C:""")+1] & @CRLF ; Drive.
$str &= "C: >> " & $a[_WinAPI_PathFileExists("C:")+1] & @CRLF ; Drive.
$str &= @ProgramFilesDir & " >> " & $a[_WinAPI_PathFileExists(@ProgramFilesDir)+1] & @CRLF ; Directory.
$str &= """Z:File.txt"" >> " & $a[_WinAPI_PathFileExists("""Z:File.txt""")+1] & @CRLF ; Shouldn't exist!
$str &= "D:bank >> " & $a[_WinAPI_PathFileExists("D:bank")+1] & @CRLF
$str &= "L: >> " & $a[_WinAPI_PathFileExists("L:")+1] & @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[0]
EndFunc   ;==>_WinAPI_PathFileExists
[/au3]
发表于 2014-2-11 15:13:00 | 显示全部楼层
进来学习一下!!!!!!!!!!!!!!!1
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-20 06:25 , Processed in 0.081451 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表