写了就发,硬盘挂了,工作白忙;X查看——短文件名(还是整合不了,加了2个自定义函数协助处理);类原有系统取短名函数功能!
#include <Constants.au3>
$f="f:\我的文档\『 提问交流 』 - AUTOIT CN AutoIt中文论坛acnau3软件汉化 - 分享您的技术!.url"
$f="f:\我的文档\『 提问交流 』 - AUTOIT CN AutoIt中文论坛acnau3软件汉化 - 分享您的技术!.URL"
$_FileGetShortName = _FileGetShortName($f)
If @error Then MsgBox(0,"出错啦!",@CR&"指定的名称错误或不存在."&@CR)
;;
$_FileGetShortName = InputBox("_FileGetShortName()","<"&$f&">"&@CR&@CR&"取得的短文件名为:",$_FileGetShortName)
Func _FileGetShortName($filename)
Local $fp=StringSplit($filename,""), $fpp,$fps,$ros, $fp2,$fps2,$string,$foo,$line,$ros1,$ros2,$ros3
If $fp[$fp[0]]<>"" then
$fpp=""
$c=$fp[0]
Else
$fpp=""
$c=$fp[0]-1
EndIf
For $i=1 To $c
If $fps<>"" Then $fps &= ""
$fps &= $fp[$i]
$ros = $fp[$i]
$ros = StringSplit($ros,".")
If @error<>1 Then
If _StringLen($ros[1])<9 And _StringLen($ros[2])<4 And $ros[0]<3 Then ContinueLoop ;
Else
If _StringLen($fp[$i])<9 Then ContinueLoop ;字符长度9个以内不处理,处理也是错误!
EndIf
If $i>1 Then
$fp2=StringSplit($fps,"")
$fps2=""
For $j=1 To $fp2[0]-1
$fps2 &= $fp2[$j]&""
Next
$string='FOR /F "eol=; tokens=2,3* delims=]" %i in ('&"'dir/x/n "& $fps2 &' ^| find /i /n "'& $fp2[$fp2[0]] &'" '&"') do @ECHO %i"
$foo = Run(@ComSpec & " /c "&$string, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$line=""
While 1
$line &= StdoutRead($foo)
If @error Then ExitLoop;(StdioClose($foo))
Wend
$line = StringSplit ( $line, @CR, 0)
$ros3=""
For $j=1 To $line[0]
$ros3 = $line[$j]
$ros1 = StringReplace($ros3, _StringLeft($ros3, 36) ,"")
$ros2= StringReplace($ros1, _StringLeft($ros1, 13) ,"")
$ros1 = StringStripWS ( _StringLeft($ros1, 13) , 8 )
If $j > 1 Then
If StringInStr($ros2,$fp2[$fp2[0]]) >1 Then ExitLoop ;匹配以空白符开头的名称(差出1字节)
Else
If StringInStr($ros2,$fp2[$fp2[0]]) =1 Then ExitLoop
EndIf
Next
$fps = $fps2&$ros1
EndIf
Next
If FileExists($fps&$fpp) Then Return $fps&$fpp ;"检测文件存在!返回字符串"
SetError(1)
Return "" ;"错误!返回空 并设 @error=1 ,……指定的文件(夹)不存在.
EndFunc
Func _StringLen($string) ;计算字串长度
Local $str=StringSplit($string,"")
Local $len=0
For $i=1 To $str[0]
$len += 1
If StringIsASCII ($str[$i]) = 0 Then $len += 1
Next
Return $len
EndFunc
Func _StringLeft($string, $len) ;按长度左取字串
Local $ret, $str = StringSplit($string,"")
$x=1
Do
If $x<$str[0] Then
$ret &= $str[$x]
If StringIsASCII ($str[$x]) = 0 Then $len -= 1
EndIf
$x += 1
$len -= 1
Until $len <= 0
If $ret="" Then Return SetError(1)
Return $ret
EndFunc
|