level 2
不需要按名字分类啥的,就随便每个文件夹1000就行
2021年09月17日 06点09分
2
level 9
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为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'"
title %#% +%$%%$%/%_% %z%
pause
exit
#>
$count=1000;
$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;
[byte[]]$b=@(32,45,45,62,32);
$c=[Text.Encoding]::Default.GetString($b);
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$files=@(dir -liter $path|?{($_.Name -ne $self.Name) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
$list=[ExpDir]::Sort($files);
$n=1;
for($i=0;$i -lt $list.Count;$i++){
$file=$path+'\'+$list[$i];
$newpath=$path+'\'+$n.toString();
if(-not (test-path -liter $newpath)){[void](md $newpath -force);};
$list[$i]+$c+$n.toString();
if((($i+1) % $count) -eq 0){$n++;};
};
2021年09月17日 06点09分
4
哎,大神,编码怎么选择的?我改完直接执行虽然新建了文件夹但是文件没有移动过去,是编码的问题么?
2021年09月17日 06点09分
编码找到在哪里选了,可还是老样子啊?那里的问题……文件是csv的格式,跟这个有关系么?
2021年09月17日 06点09分
@qop_dob 大神,为什么跑完了bat,创建了文件夹,但文件夹里都是空。文件没移动到新创建的文件夹里
2022年04月30日 17点04分