level 1
怎么将N个文件夹里的图片,前几张统一改为同一个名字,后几张改为同一个名字。比如说每个文件夹里都有猫狗猪的照片,然后统一把第一张改为猫,第二张改为狗,第三张改为猪,
2022年04月16日 15点04分
1
level 9
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起双击运行
<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 将多个文件夹里图片文件按照顺序以若干个文件作为一组重命名为一个相同指定名称
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|Out-String|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$relation=@"
1=猫
2=狗
3=猪
"@;
$dic=New-Object 'System.Collections.Generic.Dictionary[string, string]';
$arr=$relation.trim() -split '[\r\n]+';
for($i=0;$i -lt $arr.length;$i++){
$brr=$arr[$i].split('=',2);
$crr=$brr[0] -split '[~-]';
$start=[int]$crr[0];
$end=[int]$crr[0];
if($crr.length -ge 2){$end=[int]$crr[1];}
for($j=$start;$j -le $end;$j++){
$key=$j.ToString();
if(-not $dic.ContainsKey($key)){$dic.add($key, $brr[1]);}
}
}
$codes=@'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public static class ExpDir
{
[DllImport("Shlwapi.dll", CharSet=CharSet.Unicode)]
public static extern int StrCmpLogicalW(string p1, string p2);
public static string[] Sort(string[] f)
{
Array.Sort(f, StrCmpLogicalW);
return f;
}
}
'@;
Add-Type -TypeDefinition $codes;
$current=get-item -literal $env:current;
$ext=@('.jpg','.jpeg','.bmp','.png','.gif','.webp','.tif','.tiff');
$b=[Convert]::FromBase64String("IC0tPiA=");
$c=[Text.Encoding]::Default.GetString($b);
$folders=@(dir -literal $current.FullName|?{$_ -is [System.IO.DirectoryInfo]});
for($i=0;$i -lt $folders.length;$i++){
$files=@(dir -literal $folders[$i].FullName|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files.length -ge 1){
$err=[ExpDir]::Sort($files);
for($j=0;$j -lt $err.count;$j++){
$e='';
$m=[regex]::match($err[$j], '\.[^\.]+$');
if($M.Success){$e=$m.groups[0].value.ToLower();}
$key=($j+1).ToString();
if($dic.ContainsKey($key)){
if(-not [string]::IsNullOrWhiteSpace($dic[$key])){
$folders[$i].FullName+'\'+$err[$j]+$c+$dic[$key]+$e;
}
}
}
}
}
2022年04月16日 17点04分
2
谢谢,刚把贴吧下载回来,感谢感谢
2022年06月06日 02点06分