深夜读书会

 找回密码
 注册
搜索
查看: 607|回复: 1

[讨论] 最近文件的重命名有点问题就做了个脚本试试,不知为何就变好了

[复制链接]

28

主题

106

帖子

3220

积分

吃书妖怪

Rank: 5Rank: 5Rank: 5

积分
3220
贡献
3220
金币
3692
发表于 2021-10-19 20:45:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
在电脑看漫画图片时,有时候会碰到长度不一样的数字排列,比如这种:
1.jpg
2.jpg
.
.
.
21.jpg
像这种排列,看图软件是按数字大小顺序打开图片,但在重命名时很多软件就是按字符的顺序了,10会比2排位更前
为了根治数字位数长度不对看着不舒服症,做了个脚本试试,发现效果还可以,有兴趣的可以来研究,是vbs脚本
  1. Set objFSO = CreateObject("Scripting.FileSystemObject")
  2. Set Dic = CreateObject("Scripting.Dictionary")
  3. Input=WScript.Arguments(0)

  4. For Each i in objFSO.GetFolder(Input).files
  5.   f=f+1
  6.   fb=objFSO.GetBaseName(i)
  7.   For r=1 to Len(fb)
  8.     w=Mid(fb,Len(fb)-r+1,1)
  9.     If IsNumeric(w) and sufstat<>1 Then
  10.       sufstat=1
  11.       sufstr=Right(fb,r-1)
  12.       numstrsuf=Len(fb)-r+1
  13.     End If
  14.     If not IsNumeric(w) and sufstat=1 and prestat<>1 Then
  15.       prestat=1
  16.       prestr=Left(fb,Len(fb)-r+1)
  17.       numstrpre=Len(fb)-r+1
  18.     End If
  19.     If sufstat=1 and prestat=1 Then Exit For
  20.   Next
  21.   If prestat=Empty Then
  22.     prestr=Empty
  23.     numstrpre=0
  24.   End If
  25.   numstrlen=numstrsuf-numstrpre
  26.   numstr=Mid(fb,numstrpre+1,numstrlen)
  27.   If sufstat=Empty or numstr=Empty Then
  28.     wscript.echo i.path&vbCrLf&vbCrLf&"not exist number-string"
  29.     wscript.quit
  30.   End If
  31.   numlen=numstrlen
  32.   sufstat=Empty
  33.   prestat=Empty
  34.   numstr=Empty
  35.   numstrsuf=Empty
  36.   numstrpre=Empty
  37.   numstrlen=Empty
  38.   If f=1 Then Exit For
  39. Next

  40. For Each i in objFSO.GetFolder(Input).files
  41.   fb=objFSO.GetBaseName(i)
  42.   For r=1 to Len(fb)
  43.     w=Mid(fb,Len(fb)-r+1,1)
  44.     If IsNumeric(w) and sufstat<>1 Then
  45.       sufstat=1
  46.       suf=Right(fb,r-1)
  47.       numstrsuf=Len(fb)-r+1
  48.     End If
  49.     If not IsNumeric(w) and sufstat=1 and prestat<>1 Then
  50.       prestat=1
  51.       pre=Left(fb,Len(fb)-r+1)
  52.       numstrpre=Len(fb)-r+1
  53.     End If
  54.     If sufstat=1 and prestat=1 Then Exit For
  55.   Next
  56.   If prestat=Empty Then
  57.     pre=Empty
  58.     numstrpre=0
  59.   End If
  60.   numstrlen=numstrsuf-numstrpre
  61.   numstr=Mid(fb,numstrpre+1,numstrlen)
  62.   If sufstat=Empty or numstr=Empty Then
  63.     wscript.echo i.path&vbCrLf&vbCrLf&"not exist number-string"
  64.     wscript.quit
  65.   End If
  66.   If prestr<>pre or sufstr<>suf Then
  67.     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
  68.     wscript.quit
  69.   End If
  70.   If numstrlen>numlen Then numlen=numstrlen
  71.   suf=Empty
  72.   pre=Empty
  73.   sufstat=Empty
  74.   prestat=Empty
  75.   numstr=Empty
  76.   numstrsuf=Empty
  77.   numstrpre=Empty
  78.   numstrlen=Empty
  79. Next

  80. For Each i in objFSO.GetFolder(Input).files
  81.   fb=objFSO.GetBaseName(i)
  82.   ext=objFSO.GetExtensionName(i)
  83.   numvar=Mid(fb,Len(prestr)+1,Len(fb)-Len(prestr)-Len(sufstr))
  84.   ntp=numlen
  85.   stg=string(ntp,"0")
  86.   numstr=Right(stg&numvar,ntp)
  87.   namestr=prestr&numstr&sufstr&"."&ext
  88.   If not Dic.Exists(namestr) Then
  89.     Dic.Add namestr,null
  90.    Else
  91.     wscript.echo "duplicate file-name:"&vbCrLf&vbCrLf&namestr
  92.     wscript.quit
  93.   End If
  94.   numvar=Empty
  95.   numstr=Empty
  96.   namestr=Empty
  97. Next
  98. Dic.RemoveAll

  99. For Each i in objFSO.GetFolder(Input).files
  100.   Dic.Add i.name,null
  101. Next
  102. amount=0
  103. For Each i in objFSO.GetFolder(Input).files
  104.   fb=objFSO.GetBaseName(i)
  105.   ext=objFSO.GetExtensionName(i)
  106.   If Dic.Exists(i.name) Then
  107.     numvar=Mid(fb,Len(prestr)+1,Len(fb)-Len(prestr)-Len(sufstr))
  108.     ntp=numlen
  109.     stg=string(ntp,"0")
  110.     numstr=Right(stg&numvar,ntp)
  111.     namestr=prestr&numstr&sufstr&"."&ext
  112.     ftn=Left(i.path,Len(i.path)-Len(i.name))&namestr
  113.     If not objFSO.FileExists(ftn) Then
  114.       i.name=namestr
  115.       amount=amount+1
  116.     End If
  117.     numvar=Empty
  118.     numstr=Empty
  119.     namestr=Empty
  120.   End If
  121. Next

  122. wscript.echo amount&" files renamed"
复制代码


研究之前,记得先备份文件
回复

使用道具 举报

3

主题

161

帖子

1856

积分

图书委员

Rank: 4Rank: 4

积分
1856
贡献
1856
金币
8429
发表于 2021-10-20 00:00:40 | 显示全部楼层
我的电脑里这种数字1、2……10、11都是照着顺序来排列的,但是到了第一卷这种名称时就会乱序,变成一、二、三、五、六、四这样的排序,实在是不知道该说什么才好。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|ritdon

GMT+8, 2024-4-27 17:14 , Processed in 0.174887 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表