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
#>
$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
$b=[Convert]::FromBase64String("IC0tPiA=")
$c=[Text.Encoding]::Default.GetString($b)
$suffix='-00'
$current=$env:current
$folders=@(dir -literal $current -recurse|?{$_ -is [System.IO.DirectoryInfo]})
for($i=0$i -lt $folders.length$i++){
$files=@(dir -literal $folders[$i].FullName|?{$_ -is [System.IO.FileInfo]})
if($files.length -ge 1){
$arr=[ExpDir]::Sort($files)
$oldfile=get-item -literal ($folders[$i].FullName+'\'+$arr[$arr.count-1])
$base=$oldfile.BaseName -replace ([regex]::Escape($suffix)+'$'),''
$oldfile.FullName.replace($current,'')+$c+$base+$suffix+$oldfile.Extension
}
}
不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本塌差纯,另存为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
#>
$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
$b=[Convert]::FromBase64String("IC0tPiA=")
$c=[Text.Encoding]::Default.GetString($b)
$current=$env:current
$folders=@(dir -literal $current|?{$_ -is [System.IO.DirectoryInfo]})
for($i=0$i -lt $folders.length$i++){
团咐$files=@(dir -literal $folders[$i].FullName|?{$_ -is [System.IO.FileInfo]}|%{$_.Name})
if($files.length -ge 1){
write-host $folders[$i].FullName -ForegroundColor yellow
$arr=[ExpDir]::Sort($files)
for($j=0$j -lt $arr.Count$j++){
$ext=''
$m=[regex]::match($arr[$j], '\.[^\.]+$')
if($m.Success){$ext=$m.groups[0].value}
$newname=$folders[$i].Name+'_'+($j+1).ToString()+$ext
$arr[$j]+$c+$newname
}
write-host ''
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)