本帖最后由 pcl_test 于 2016-7-15 20:34 编辑
- /*&cls
- @echo off
- rem 以文件名中自左向右首个出现的数字串为修改对象
- dir /a-d /b *.txt|cscript -nologo -e:jscript "%~f0"
- pause&exit
- */
-
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var f=[], i=0, zero='00000000000000000000', t;
- while(!WSH.StdIn.AtEndOfStream){
- var file = fso.GetFile(WSH.StdIn.ReadLine());
- //获取数字串最长位数
- if(/\D*(\d+).+/.test(file.Name)){
- if(typeof(n) == 'undefined'){
- n = RegExp.$1.length
- }else{
- if(RegExp.$1.length > n)n=RegExp.$1.length;
- }
- f[i] = file;
- i++;
- }
- }
-
- for(i--; i>=0; i--){
- var newname = f[i].Name.replace(/\d+/, function(num){t = num.length;return (zero+num).slice(-n)});
- if(t < n)f[i].Name = newname;
- }
- WSH.echo('Done');
复制代码
|