|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
在电脑看漫画图片时,有时候会碰到长度不一样的数字排列,比如这种:
1.jpg
2.jpg
.
.
.
21.jpg
像这种排列,看图软件是按数字大小顺序打开图片,但在重命名时很多软件就是按字符的顺序了,10会比2排位更前
为了根治数字位数长度不对看着不舒服症,做了个脚本试试,发现效果还可以,有兴趣的可以来研究,是vbs脚本
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set Dic = CreateObject("Scripting.Dictionary")
- Input=WScript.Arguments(0)
- For Each i in objFSO.GetFolder(Input).files
- f=f+1
- fb=objFSO.GetBaseName(i)
- For r=1 to Len(fb)
- w=Mid(fb,Len(fb)-r+1,1)
- If IsNumeric(w) and sufstat<>1 Then
- sufstat=1
- sufstr=Right(fb,r-1)
- numstrsuf=Len(fb)-r+1
- End If
- If not IsNumeric(w) and sufstat=1 and prestat<>1 Then
- prestat=1
- prestr=Left(fb,Len(fb)-r+1)
- numstrpre=Len(fb)-r+1
- End If
- If sufstat=1 and prestat=1 Then Exit For
- Next
- If prestat=Empty Then
- prestr=Empty
- numstrpre=0
- End If
- numstrlen=numstrsuf-numstrpre
- numstr=Mid(fb,numstrpre+1,numstrlen)
- If sufstat=Empty or numstr=Empty Then
- wscript.echo i.path&vbCrLf&vbCrLf&"not exist number-string"
- wscript.quit
- End If
- numlen=numstrlen
- sufstat=Empty
- prestat=Empty
- numstr=Empty
- numstrsuf=Empty
- numstrpre=Empty
- numstrlen=Empty
- If f=1 Then Exit For
- Next
- For Each i in objFSO.GetFolder(Input).files
- fb=objFSO.GetBaseName(i)
- For r=1 to Len(fb)
- w=Mid(fb,Len(fb)-r+1,1)
- If IsNumeric(w) and sufstat<>1 Then
- sufstat=1
- suf=Right(fb,r-1)
- numstrsuf=Len(fb)-r+1
- End If
- If not IsNumeric(w) and sufstat=1 and prestat<>1 Then
- prestat=1
- pre=Left(fb,Len(fb)-r+1)
- numstrpre=Len(fb)-r+1
- End If
- If sufstat=1 and prestat=1 Then Exit For
- Next
- If prestat=Empty Then
- pre=Empty
- numstrpre=0
- End If
- numstrlen=numstrsuf-numstrpre
- numstr=Mid(fb,numstrpre+1,numstrlen)
- If sufstat=Empty or numstr=Empty Then
- wscript.echo i.path&vbCrLf&vbCrLf&"not exist number-string"
- wscript.quit
- End If
- If prestr<>pre or sufstr<>suf Then
- wscript.echo i.path&vbCrLf&vbCrLf&"not match presuf string"&vbCrLf&vbCrLf&"first-prestr="&prestr&vbCrLf&"first-sufstr="&sufstr&vbCrLf&vbCrLf&"current-pre="&pre&vbCrLf&"current-suf="&suf
- wscript.quit
- End If
- If numstrlen>numlen Then numlen=numstrlen
- suf=Empty
- pre=Empty
- sufstat=Empty
- prestat=Empty
- numstr=Empty
- numstrsuf=Empty
- numstrpre=Empty
- numstrlen=Empty
- Next
- For Each i in objFSO.GetFolder(Input).files
- fb=objFSO.GetBaseName(i)
- ext=objFSO.GetExtensionName(i)
- numvar=Mid(fb,Len(prestr)+1,Len(fb)-Len(prestr)-Len(sufstr))
- ntp=numlen
- stg=string(ntp,"0")
- numstr=Right(stg&numvar,ntp)
- namestr=prestr&numstr&sufstr&"."&ext
- If not Dic.Exists(namestr) Then
- Dic.Add namestr,null
- Else
- wscript.echo "duplicate file-name:"&vbCrLf&vbCrLf&namestr
- wscript.quit
- End If
- numvar=Empty
- numstr=Empty
- namestr=Empty
- Next
- Dic.RemoveAll
- For Each i in objFSO.GetFolder(Input).files
- Dic.Add i.name,null
- Next
- amount=0
- For Each i in objFSO.GetFolder(Input).files
- fb=objFSO.GetBaseName(i)
- ext=objFSO.GetExtensionName(i)
- If Dic.Exists(i.name) Then
- numvar=Mid(fb,Len(prestr)+1,Len(fb)-Len(prestr)-Len(sufstr))
- ntp=numlen
- stg=string(ntp,"0")
- numstr=Right(stg&numvar,ntp)
- namestr=prestr&numstr&sufstr&"."&ext
- ftn=Left(i.path,Len(i.path)-Len(i.name))&namestr
- If not objFSO.FileExists(ftn) Then
- i.name=namestr
- amount=amount+1
- End If
- numvar=Empty
- numstr=Empty
- namestr=Empty
- End If
- Next
- wscript.echo amount&" files renamed"
复制代码
研究之前,记得先备份文件 |
|