本帖最后由 WHY 于 2019-10-23 14:40 编辑
PowerShell 脚本- $fdPath = 'E:\Test'; #待处理的文件夹路径
- $max = 500; #每个文件夹保留的最大文件数
-
- forEach( $fd In (dir -Literal $fdPath -Recurse | ?{$_ -is [IO.DirectoryInfo]}) ){
-
- $file = [IO.Directory]::GetFiles($fd.FullName);
- if( $file.Count -lt $max ) { continue; }
- $n = 0;
- $count = $file.Count / $max;
-
- for( $i=1; $i -lt $count; $i++ ){
- $start = $i * $max;
- $end = ($i + 1) * $max - 1;
- $newFolder = $fd.FullName + '(' + ++$n + ')';
- while( [IO.Directory]::Exists($newFolder) ){ $newFolder = $fd.FullName + '(' + ++$n + ')'; }
- $null = md $newFolder;
- move -Literal $file[$start..$end] -Dest $newFolder;
- }
- }
-
- echo 'Done';
- [Console]::ReadKey();
复制代码
|