批处理,如图怎么把现有文件夹按前7位相同批量归类到新文件夹?

如图有很多文件夹,前7位是字母数字组成,需要先新建以前7位命名的文件夹,然后把前7位相同的文件夹都移到这个文件夹内,

不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起双击运行
<# :
cls&echo off&mode con lines=5000
rem 将当前目录里名称开头前几位字符相同的多个子文件夹剪切/归类/移动到同一个以相同字符命名的新文件夹里
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
set "folder=."
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$len="7";
$path=get-item -liter $env:folder;
[byte[]]$b=@(32,45,45,62,32);
$c=[Text.Encoding]::Default.GetString($b);
$folders=@(dir -liter $path.FullName|?{$_ -is [System.IO.DirectoryInfo]});
$reg='^(.{'+$len+'}).+';
for($i=0;$i -lt $folders.length;$i++){
$m=[regex]::match($folders[$i].Name,$reg);
if($m.Success){
$newfolder=$path.FullName+'\'+$m.groups[1].value;
if(-not (test-path -liter $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder)};
$folders[$i].Name+$c+$m.groups[1].value;
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答