简体   繁体   English

根据名称批量移动文件到新的子文件夹

[英]Batch move files to new subfolders based on name

I'm using Windows 7 and I have half a million images stored in one folder "C:\\capture".我使用的是 Windows 7,并且在一个文件夹“C:\\capture”中存储了 50 万张图像。 These images forms 330 image sequences and they are named as follows:这些图像形成了 330 个图像序列,它们的命名如下:

1.0000000000.png 
...
1.0000003299.png
... ...
330.0000000000.png
...
330.0000000010.png

I would like to move these into 330 subfolders named after the first part of the names.我想将这些移动到以名称的第一部分命名的 330 个子文件夹中。

C:\capture\1\1.0000000000.png 
...
C:\capture\1\1.0000003299.png
... ...
C:\capture\330\330.0000000000.png
...
C:\capture\330\330.0000000010.png

So I'm basically only interested in everything before the first '.'所以我基本上只对第一个 '.' 之前的所有内容感兴趣。 in the names.在名称中。 How do I write a batch file that creates the subfolders and moves the corresponding files into them?如何编写创建子文件夹并将相应文件移动到其中的批处理文件?

To be executed from command line inside the directory to be processed (better if you try with a copy)从要处理的目录内的命令行执行(如果您尝试使用副本更好)

for /l %a in (1 1 330) do (md %a 2>nul & if exist %a\ move /y "%a.*.png" %a\ )

If you want to use it inside a batch file, percent signs need to be escaped, replacing all %a with %%a如果要在批处理文件中使用它,则需要转义百分号,将所有%a替换为%%a

for /l %%a in (1 1 330) do (
    md %%a 2>nul 
    if exist %%a\ move /y "%%a.*.png" %%a\ 
)

It will generate all the prefixes and for each one execute a move command to move the matching files to the final folder (previously created)它将生成所有前缀,并为每个前缀执行一个移动命令将匹配的文件移动到最终文件夹(之前创建的)

Here is a more general batch script, that is boundary agnostic , in the sense that it will automatically decide how many subfolders have to be created, based on the "prefixes" of the images, so you don't have to modify it in case the number of image sequences changes.这是一个更通用的批处理脚本,即边界不可知,从某种意义上说,它将根据图像的“前缀”自动决定必须创建多少个子文件夹,因此您不必修改它以防万一图像序列的数量发生变化。

@echo off

set DIR="C:\capture"
pushd %DIR%
setlocal ENABLEDELAYEDEXPANSION
for %%g in (*.png) do (
    set t=%%~nxg
    for /F "delims=." %%a in ("!t!") do (
        if not exist %%a (md %%a)
        move !t! %%a > nul
    )
)
endlocal
popd

Taking my inspiration from sokins answer, I'll weigh in with this effort...从 sokins 的答案中汲取灵感,我会为此努力……

@echo off
setlocal enabledelayedexpansion

for %%i in (C:\capture\*.png) do (
    for /f "tokens=3 delims=.\" %%a in ('echo %%i') do (
    set prefix=%%a
    if not exist C:\capture\!prefix! md C:\capture\!prefix!
    move "%%i" C:\capture\!prefix!
) 
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理子文件夹中的 OCR 文件并使用新名称保存新文件 - Batch OCR files in subfolders and save new files with new name BATCH在子文件夹中查找字符串并移动到新位置 - BATCH Find string in subfolders and move to new location 批处理文件根据文件名创建目录,将类似文件移动到新目录 - batch file to create directory based on file name, move like files to new directory BAT脚本按文件名将文件移动到子文件夹中 - BAT script to move files into subfolders by file name 批量创建子文件夹并将父图像文件复制到新的子文件夹 - batch create subfolders and copy parent image files to new subfolders 批量创建基于部分文件名的文件夹并将文件移动到该文件夹​​中 - Batch create folders based on part of file name and move files into that folder 根据部分文件名批量创建文件夹并将文件移动到文件夹 - Batch create folder based on partial file name and move files to folder Windows批处理 - 根据文件名和扩展名将文件移动到文件夹 - Windows batch - Move files to folders based on file name & extension 批处理将文件移动到随机命名的子文件夹之外 - Batch to move files outside of randomly-named subfolders 根据Win7中的列表自动将文件移动到各个子文件夹 - Automated move of files to various subfolders based on list in Win7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM