batch-file - 将包含许多文件的文件夹拆分为多个子文件夹 (Windows 10)

标签 batch-file windows-10 windows-explorer

我有一个包含 110.000 个文件的文件夹,我想要一种方法将此文件夹分成多个子文件夹,每个子文件夹包含 3000 个文件(也许使用批处理脚本?)。 (尝试使用 WinExplorer 进行复制/粘贴会卡在“准备复制”中。)

例如:

BigFolder
  |
NewFolder
|     |    |    |    |
Sub1  Sub2 Sub3 Sub4 Sub5...

最佳答案

我很惊讶地发现我的情况相同。 我有 30,000 个文件需要排序,所以我在这个页面上提问: Fast methods to copy(move) files in batch file

这是 Compo的脚本:

@Echo Off
If /I Not "%__CD__%"=="%~dp0" PushD "%~dp0" 2>Nul||Exit/B
SetLocal EnableDelayedExpansion
Set "DirN=-1"

:Check_DirN
Set/A "DirN+=1"
If Exist "%DirN%" GoTo Check_DirN
Set "limit=700"
For %%A In (*.bat *.cmd *.txt) Do (
    If Not Exist "%DirN%" MD "%DirN%"
    If /I Not "%%~nxA"=="%~nx0" RoboCopy . "%DirN%" "%%A" /MOV 1>NUL
    Set/A "limit-=1"
    If !limit! Lss 0 GoTo Check_DirN
)
Echo(Task Done!
Timeout -1 1>Nul

这就是我使用的内容,并为此目的进行了一些编辑:

@Echo Off
If /I Not "%__CD__%"=="%~dp0" PushD "%~dp0" 2>Nul||Exit/B
taskkill /f /im explorer.exe >nul
taskkill /f /im SearchIndexer.exe >nul
sc stop WSearch >nul
sc config WSearch start= disabled >nul

SetLocal EnableDelayedExpansion
Set "DirN=-1"

:Check_DirN
Set/A "DirN+=1"
If Exist "%DirN%" GoTo Check_DirN
cls
echo Moving files to Directory %DirN%...
Set "limit=2999"
MD "%DirN%"
For %%A In (*.html) Do (
    RoboCopy . "%DirN%" "%%A" /MOV 1>NUL
    Set/A "limit-=1"
    If !limit! Lss 0 GoTo Check_DirN
)
Echo(Task Done!

start explorer.exe
start SearchIndexer.exe
sc config WSearch start= delayed-auto >nul
sc start WSearch >nul
Timeout -1 1>Nul

如果需要,您可以删除 taskkillstartsc 部分。 我添加这部分是因为资源管理器和Windows Search Indexer 在移动文件时会造成内存浪费。我建议您以管理员权限运行脚本。

尝试小规模测试脚本,看看它是否有效。

关于batch-file - 将包含许多文件的文件夹拆分为多个子文件夹 (Windows 10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41501947/

相关文章:

windows - 如何找出谁在运行 runas 应用程序?

windows - 在Windows中使用批处理文件编程执行exe文件后如何锁定计算机?

java - netbeans、cmd 和 .bat 或 .cmd 中的路径差异

visual-studio-2013 - Visual Studio 2013 语言包安装失败 : Program Compatibility Mode is on (Windows 10)

c# - 从 .NET 以编程方式访问 "Open with"Windows 资源管理器菜单列表

c - 确定 explorer.exe 是否作为 windows shell 运行?

windows - 如何检查当前驱动器是否在本地磁盘(cmd)上?

java - WSL2 上的 Maven 看不到 JAVA_HOME

ssl - 将用户证书导入 windows 10 可信根证书

visual-studio - Windows 资源管理器 - 相同文件扩展名的动态图标