本帖最后由 gzh888666 于 2014-12-19 10:09 编辑
以前学的点正则全还回去了,重新学习,请教要实现替换扩展名,并且根据相应的扩展名替换文件名的第一位,再根据文件的第一位还原扩展名。
au3.au3.rmvb
替换为
1u3.au3.rar
然后
1u3.au3.rar
再替换回
1u3.au3.rmvb
#region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_icon=C:\Windows\system32\SHELL32.dll|-24
#AutoIt3Wrapper_Outfile=E:\moveFild.a3x
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
;视频保存转换
#include <Array.au3>
#include <File.au3>
Dim $jiance ;用于检测是否是压缩文件,0为是,1为不是
$lujing = "E:\360驱动大师目录\驱动备份\"
$wenjian = _FileListToArray($lujing, "*", 1)
;_ArrayDisplay($wenjian)
If _TiQuKuoZhanMing($wenjian[1]) <> "rar" Then
For $n = 1 To UBound($wenjian) - 1
$kuozhanming = _TiQuKuoZhanMing($wenjian[$n])
$ChangDu = StringLen($kuozhanming)
$xinlujing = StringTrimRight($wenjian[$n], $ChangDu) & "rar"
If _kuozhanming_xuliehao_huhuan($kuozhanming) <> "" Then
$xinlujing = _kuozhanming_xuliehao_huhuan($kuozhanming) & StringTrimLeft($xinlujing, 1)
FileMove($lujing & $wenjian[$n], $lujing & $xinlujing)
Else
MsgBox(0, "", "("& $wenjian[$n] & ")的扩展名未添加到源码!")
EndIf
$jiance = 1
Next
Else
For $n = 1 To UBound($wenjian) - 1
$diyiwei = StringLeft($wenjian[$n], 1)
If _kuozhanming_xuliehao_huhuan($diyiwei) <> "" Then
$xinlujing = StringTrimRight($wenjian[$n], 3) & _kuozhanming_xuliehao_huhuan($diyiwei)
FileMove($lujing & $wenjian[$n], $lujing & $xinlujing)
Else
MsgBox(0, "", "("& $wenjian[$n] & ")的扩展名丢失!请手动更换尝试!")
EndIf
$jiance = 0
Next
EndIf
If $jiance = 0 Then
If MsgBox(1, "", "你确定要打开文件夹吗?") = 1 Then _ExplorerDir($lujing)
ElseIf $jiance = 1 Then
MsgBox(0, "", "现在是压缩文件", 3)
EndIf
Func _kuozhanming_xuliehao_huhuan($qian);返回扩展名对应的序列号互换结果
Local $zhuanhuanhou = ""
Switch $qian
Case "rmvb"
$zhuanhuanhou = "1"
Case "mp4"
$zhuanhuanhou = "2"
Case "avi"
$zhuanhuanhou = "3"
Case "wmv"
$zhuanhuanhou = "4"
Case "1"
$zhuanhuanhou = "rmvb"
Case "2"
$zhuanhuanhou = "mp4"
Case "3"
$zhuanhuanhou = "avi"
Case "4"
$zhuanhuanhou = "wmv"
EndSwitch
If $zhuanhuanhou <> "" Then
Return $zhuanhuanhou
Else
Return ""
EndIf
EndFunc ;==>_kuozhanming_xuliehao_huhuan
Func _TiQuKuoZhanMing($str)
$Test = StringRegExp($str, '\.([^\.]*)$', 3)
Return $Test[0]
EndFunc ;==>_TiQuKuoZhanMing
Func _ExplorerDir($Dir, $Parameter = 0)
Switch $Parameter
Case 0
ShellExecuteWait("Explorer", "/n, " & $Dir)
Case 1
ShellExecuteWait("Explorer", "/e, " & $Dir)
Case 2
ShellExecuteWait("Explorer", "/root, " & $Dir)
Case 3
ShellExecuteWait("Explorer", "/select, " & $Dir)
Case Else
MsgBox(262160, "提示", " 参数错误! ")
EndSwitch
EndFunc ;==>_ExplorerDir
|