本帖最后由 WHY 于 2016-7-6 01:17 编辑
powershell 可以这样:- $arr = dir *.txt | ?{$_ -is [IO.FileInfo]} #### 遍历当前目录下的txt文件
- $num = 7 #### 每7个文件一组
-
- $chr = 'ABCEFGHIJLMNOPQSTUVWYZDKRX'.ToCharArray()
- $i = 0
-
- while ($arr[$i] -ne $null) {
- $flag = 1
- $arr[$i..($i + $num - 1)] | get-Random -Count $num | %{
- $str = ($chr | get-Random -Count 26) -join(''); $str *= 2;
- if ($flag) {
- $flag = 0
- $str = [regex]::match($str, '....[DKRX]').value
- } else {
- $str = [regex]::match($str, '....[^DKRX]').value
- }
- $newName = $_.Name -replace '(.+)(\..+)$', ('$1' + $str + '$2')
- ren $_ -newName $newName
- }
- $i += $num
- }
复制代码
- @if (0)==(0) echo off
- dir /b *.txt | cscript //nologo //e:jscript "%~0"
- pause & exit
- @end
-
- var num = 7; //每7个文件一组
- var chr = 'ABCEFGHIJLMNOPQSTUVWYZDKRX'.match(/./g);
-
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var arr = WSH.StdIn.ReadAll().replace(/\r\n$/, '').split('\r\n');
-
- while(arr.length > 0){
- var m = arr.slice(0, num);
- m.sort(function(){return Math.random() - 0.5});
- for (var i=0; i<m.length; i++) {
- var s = chr.sort(function(){return Math.random() - 0.5}).join(''); s += s;
- if (i==0) {
- s = s.match(/....[DKRX]/);
- } else {
- s = s.match(/....[^DKRX]/);
- }
- fso.GetFile(m[i]).Name = m[i].replace(/(.+)(\..+)$/, '$1' + s + '$2');
- }
- arr.splice(0, num);
- }
复制代码
|