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

By admin at 2020-11-24 05:12:59 • 708点击

试试VBS 脚本,复制bai以下内容,新建记事本。粘贴后保存:
类型选所有,文件名:文件名前批量.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



复制粘贴到记事本,另存为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);
}

目前尚无回复
该帖评论已关闭