#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#Region ### START Koda GUI section ### Form=E:\4_au3\K型文件夹\畸形文件夹.kxf
$Form1 = GUICreate("畸形文件夹", 394, 251, 363, 359)
$Label1 = GUICtrlCreateLabel("要搜索畸形文件夹的路径:", 8, 8, 139, 17)
$Input1 = GUICtrlCreateInput("", 152, 6, 177, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("浏览", 336, 4, 51, 25)
$Group1 = GUICtrlCreateGroup("畸形文件夹", 8, 32, 377, 193)
$List1 = GUICtrlCreateList("", 16, 48, 361, 162)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$var = FileSelectFolder("请选择:", "")
If Not @error Then
GUICtrlSetData($List1,"")
GUICtrlSetData($Input1, $var)
$_var = StringSplit($var, "")
If $_var[0] <= 2 Then
$dir = _FileListToArray($var)
For $i = 1 To $dir[0]
$kfile = StringRight($dir[$i], 1)
If $kfile = "." Then
$k=StringSplit(_FileGetShortName($var & $dir[$i]),"")
GUICtrlSetData($List1, $k [$k[0]]& "|")
EndIf
Next
Else
$var&=""
$dir = _FileListToArray($var)
For $i = 1 To $dir[0]
$kfile = StringRight($dir[$i], 1)
If $kfile = "." Then
$k=StringSplit(_FileGetShortName($var & $dir[$i]),"")
GUICtrlSetData($List1, $k[$k[0]] & "|")
EndIf
Next
EndIf
EndIf
EndSwitch
WEnd
Func _FileGetShortName($FilePath, $Flag = 1)
$FilePath = StringRegExpReplace($FilePath, '\\+$', '')
If $Flag <> 1 Then $Flag = 0
If FileExists($FilePath) And Not StringRegExp($FilePath, '\.+$') Then
If $Flag = 1 Then Return FileGetShortName($FilePath, 1)
Return StringRegExpReplace(FileGetShortName($FilePath, 1), '.+\\', '')
EndIf
Local $Path, $File
If StringInStr($FilePath, ':') Then
$Path = StringRegExpReplace($FilePath, '\\[^\\]+$', '')
$File = StringRegExpReplace($FilePath, '.+\\', '')
Else
$Path = @ScriptDir
If StringInStr($FilePath, '\') Then $Path &= '\' & StringRegExpReplace($FilePath, '\\[^\\]+$', '')
$File = StringRegExpReplace($FilePath, '.+\\', '')
EndIf
$File = StringRegExpReplace($File, '(\.|\+|\(|\)|\{|\}|\[|\]|\^|\$)', '\\$1')
Local $str = '', $too
$too = Run(@ComSpec & ' /c dir /A /x "' & $Path & '"', '', 0, 2)
While 1
Sleep(1)
$str &= StdoutRead($too)
If @error Then ExitLoop
WEnd
If Not StringRegExp($str, '<DIR>.+\s' & $File & '\r') Then Return SetError(1, 0, 0)
Local $ShortName = StringRegExpReplace($str, '(?s).+<DIR>\s+?([^\s]+)\s+?' & $File & '.+', '$1')
If @extended = 0 Then Return SetError(1, 0, 0)
If $Flag = 1 Then Return FileGetShortName($Path, 1) & '\' & $ShortName
Return $ShortName
EndFunc ;==>_FileGetShortName