文件名前批量、随机、添加序号(批处理.bat)?

大神!帮我修改下面这个批处理,它执行完后,每次都有几个文件没改成功,而且好像不支持1000+以上的文件。。。

@echo off&cd/d %~dp0&set/a n=1000
setlocal enabledelayedexpansion
for /f "tokens=1* delims=_" %%i in (
'dir/b/a-d *.mp3^|findstr/b "[0-9][0-9]*_"')do ren "%%i_%%j" "%%j"
for %%i in (*.mp3)do set "#!random!=%%i"
for /f "tokens=1* delims==" %%i in ('set #')do (
set/a n+=1
echo !n:~1!_%%j
ren "%%j" "!n:~1!_%%j"
)
set/p=按任意键退出... <nul&pause>nul

批量在文件名前添加序号(编号)的方法:

步骤1,先下载“优速文件批量重命名”工具软件,安装打开使用。点击软件中间或者【添加文件】按钮,将需要添加需要的文件批量导入到软件中,格式不受限制。

步骤2,然后可以看到左边有设置栏,命名方式选择“插入”;插入类型选择“编号”(编号即序号);然后进行编号设置,起始右边输入第一个序号,增量是下一个序号比前一个序号增加的数值;位数是序号一共几位的意思(不够的话用0凑)。这时候我们在右边可以预览到新文件名前全部添加了序号。

步骤3,当你认为设置好了后就可以点击【开始重命名】按钮,启动软件程序了。处理完成后软件会弹出“重命名成功”的提示框。

步骤4,对比处理前后的文件可以看到,处理后的文件名前面全部添加了序号。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-18
不清楚你的实际文件/情况,仅以问题中的样例/说明为据
复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起运行<# :
cls
@echo off
rem 打乱多个文件的原有排序/顺序并在文件名称开头添加递增的数字序号前缀
mode con lines=5000
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%"
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$path=$args[0].trimend('\');
$ext=@('.mp3');
$files=@(dir -liter $path|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
    $newname=$files[$i].Name -replace '^\d+_','';
    if($newname -ne $files[$i].Name){
        $newfile=$files[$i].Directory.FullName+'\'+$newname;
        if(-not (test-path -liter $newfile)){
            mv -liter $files[$i].FullName $newfile;
        };
    };
};
$n=[Math]::Pow(10, $files.length.toString().length);
$files=@(dir -liter $path|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
$list=@(get-random -input $files -count $files.length);
for($i=0;$i -lt $list.length;$i++){
    $m=$n+$i+1;
    $newname=$m.toString().Substring(1)+'_'+$list[$i].Name;
    $newfile=$list[$i].Directory.FullName+'\'+$newname;
    write-host ($list[$i].Name+' --> '+$newname);
}

来自:求助得到的回答
第1个回答  2020-04-18
试试VBS 脚本,复制以下内容,新建记事本。粘贴后保存:
类型选所有,文件名:文件名前批量.vbs,编码选择:ANSI
dim fnew,newf,arr
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(fso.GetFile(Wscript.ScriptFullName).ParentFolder.Path)
Set oFiles = oFolder.Files
ss= oFiles.count
For Each oFile In oFiles
if fso.GetExtensionName(oFile.Path) <> "mp3" then ss=ss - 1
next
arr = split(RndNub(ss),",")
newf = 0
For Each oFile In oFiles
if fso.GetExtensionName(oFile.Path) ="mp3" then
i = arr(newf)
oFile.name = left("0000", 4-len(i)) & i & "_" & oFile.name
newf = newf + 1
end if
next

msgbox "Done!",64,"TXT"

Function RndNub(ReqNub)
dim rds
Randomize
Set myList=CreateObject("System.Collections.ArrayList")
for i = 0 to 9999
myList.add(i)
next

for i=0 to ReqNub-1
index = Int((10000-i) * Rnd)
rds =rds & mylist.Item(index) & ","
myList.RemoveAt(index)
next
RndNub = rds
End Function本回答被网友采纳
相似回答