从包含数千个文件的主文件夹创建 A 到 Z 子文件夹

mis*_*gar 2 command-line automation file batch-file

主文件夹内容(示例)

apple.txt
art.txt
berry.txt
cherry.txt
coffee.txt
..,
...
...
zebra.txt
Run Code Online (Sandbox Code Playgroud)

预期输出(子文件夹)

A
  apple.txt
  art.txt
B
  berry.txt
C
  cherry.txt
  coffee.txt
...
...
...
Z
  zebra.txt
Run Code Online (Sandbox Code Playgroud)

如何通过 Windows 批处理文件完成此操作?

Ger*_*ard 6

这是我快速编写的脚本。基本上创建一个dirif不存在,然后搜索.txt脚本根目录中的所有文件,然后测试该单词的第一个字母,然后简单地将其复制到匹配目录。

@echo off
setlocal enabledelayedexpansion
for %%i in (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 (
   if not exist %%i mkdir %%i
)
for %%f in (*.txt) do (
set "file=%%f"
set "var=!file:~0,1!"
echo move "%%~dpf!file!" "%%~dpf!var!\" 
)
pause
Run Code Online (Sandbox Code Playgroud)

测试后,只需删除倒数第二行中的echobefore即可实际执行任务copycopy