回复 23# chenronting
回复 20# shano
修改了下,请你们再测试看看$_weizi = 'D:\'
$_filename = '爱什么是什么........'
DirCreate($_weizi & $_filename & './')
$_duan8 = _FileGetShortName($_weizi & $_filename)
MsgBox(0, '', $_duan8)
RunWait(@ComSpec & ' /c rd "' & $_duan8 & '" /s /q', '', 0)
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, $ShortName
$too = Run(@ComSpec & ' /c dir /A /x "' & $Path & '"', '', 0, 2)
While 1
Sleep(1)
$str = StdoutRead($too)
If @error Then ExitLoop
$ShortName = StringRegExpReplace($str, '(?s).+<DIR>\s+?([^\s]+)\s+?' & $File & '.+', '$1')
If @extended > 0 Then ExitLoop
WEnd
If @extended = 0 Then Return SetError(1, 0, 0)
If $Flag = 1 Then Return FileGetShortName($Path, 1) & '\' & $ShortName
Return $ShortName
EndFunc ;==>_FileGetShortName
|