这是我在这里的第一个帖子/请求。我已经进行了大量搜索来尝试找到解决方案,但我认为我的要求有点雄心勃勃。
我使用的是 Windows 7,并且更喜欢在 DOS 批处理文件中而不是 PowerShell 中执行此操作。
我有包含数十万个旧 Zip 存档的文件夹。由于一个文件夹中有很多文件,列出它们可能会很慢。我想将 Zip 存档移动到按字母顺序排列的文件夹中,但每个文件夹需要限制为 1000 个文件
因此前 1000 个 a*.zip 文件将被移动到名为 A1 的文件夹中。将第二千个 a*.zip 文件放入名为 A2 的文件夹中,依此类推。
文件需要按顺序移动,因此,如果复制到 A1 的最后一个文件是 an_example_file_97.zip,那么移动到 A2 文件夹的第一个文件将为 an_example_file_98.zip
我需要对整个字母表以及数字命名的 Zip 文件执行此操作。然后我最终会得到像这样的文件夹/文件结构......
<DIR> 01
1000 zip archives whose filename begins with a number
<DIR> 02
Next 1000 zip archives whose filename begins with a number
<DIR> 03
Next 1000 zip archives whose filename begins with a number
<DIR> A1
1000 zip archives whose filename begins with A
<DIR> A2
Next 1000 zip archives whose filename begins with A
<DIR> A3
Next 1000 zip archives whose filename begins with A
<DIR> B1
1000 zip archives whose filename begins with B
<DIR> B2
Next 1000 zip archives whose filename begins with B
<DIR> B3
Next 1000 zip archives whose filename begins with B
<DIR> Z1
1000 zip archives whose filename begins with Z
<DIR> Z2
Next 1000 zip archives whose filename begins with Z
<DIR> Z3
Next 1000 zip archives whose filename begins with Z
如果此解决方案已存在于该网站上,我深表歉意,但准确地知道要搜索什么内容很困难。
谢谢。
最佳答案
这是一样的LotPings' answer ,但进行了一些小修改,使其更简单、更快:
@Echo off
SetLocal EnableExtensions EnableDelayedExpansion
PushD "X:\start\here"
for %%A in (*.*) Do (
Set "Name=%%~nA"
Set "N=!Name:~0,1!"
If "!N!" lss "a" Set "N=0"
Set /A "Array[!N!]+=1, F=Array[!N!] / 1000 +1"
Set "Dest=!N!!F!"
If not Exist "!Dest!" REM MD "!Dest!"
Echo Move "%%A" "!Dest!\"
)
如果列表简单for %%A
命令未排序,则更改 for %%A in (*.*) Do (
由这两行组成:
for %%L in (0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do (
for /F "Delims=" %%A in ('Dir /B /ON %%L*') Do (
...并在末尾添加右括号。这比简单的 for /F "Delims=" %%A in ('Dir /B /ON *') Do (
更好。因为如果文件数量巨大,那么执行这样的for
可能需要太多时间...
关于batch-file - Windows 批处理文件将 1000 个文件分组到字母数字文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50820500/