本帖最后由 afan 于 2010-10-22 23:29 编辑 $_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, $ShortName, $tmp
Do
$tmp = ''
While StringLen($tmp) < 7
$tmp &= Chr(Random(97, 122, 1))
WEnd
$tmp = @TempDir & '\~' & $tmp
Until Not FileExists($tmp)
RunWait(@ComSpec & ' /c dir /A /x "' & $Path & '" > "' & $tmp & '"', @SystemDir, 0)
$str = FileRead($tmp)
FileDelete($tmp)
$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
|