level 4
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为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"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$count=4;
$ext=@('.jpg','.jpeg','.bmp','.png');
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$begin=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;
$files=@(dir -liter $path|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files.length -ge 1){
$arr=[ExpDir]::Sort($files);
for($i=0;$i -lt $arr.count;$i++){
$newfolder=$path+'\'+$begin.toString();
if(-not (test-path -liter $newfolder)){
[void](md $newfolder);
};
write-host ($arr[$i]+' --> '+$begin.toString());
if((($i+1) % $count) -eq 0){$begin++;};
};
}
2021年05月14日 17点05分