简体   繁体   English

批处理文件以在文件夹中创建新的子文件夹,将文件移动到目录中所有文件夹的新创建的子文件夹

[英]batch file to create new subfolder in folder, move file to newly created subfolder, for all folders in directory

I am needing help to move files in my library. 我需要移动库中文件的帮助。 I've searched and read for hours and can't find the proper solution, if any. 我已经搜索并阅读了几个小时,找不到合适的解决方案(如果有)。

My directory looks like this 我的目录看起来像这样

  • D:Music\\ d:音乐\\
    • D:Music\\Name - Title\\ D:音乐\\名称-标题\\
    • D:Music\\Name - Title\\xxxx.jpg D:音乐\\名称-标题\\ xxxx.jpg
    • D:Music\\Name - Title\\xxxx-type.jpg D:音乐\\名称-标题\\ xxxx-type.jpg
    • D:Music\\Name - Title\\xxxx.xml D:音乐\\名称-标题\\ xxxx.xml

There are thousands of these entries in D:Music. D:Music中有成千上万个这样的条目。 Folder names 'Name - Title' are all different. 文件夹名称“名称-标题”都是不同的。

I want to move xxxx-type.jpg to new folder named 'artwork' in the 'Name - Title' folder. 我想将xxxx-type.jpg移到“名称-标题”文件夹中名为“ artwork”的新文件夹中。 The files I want to move all end in '-type.jpg'. 我要移动的所有文件都以“ -type.jpg”结尾。

The new directory would look like this: 新目录如下所示:

  • D:Music\\ d:音乐\\
    • D:Music\\Name - Title\\ D:音乐\\名称-标题\\
    • D:Music\\Name - Title\\xxxx.jpg D:音乐\\名称-标题\\ xxxx.jpg
    • D:Music\\Name - Title\\xxxx.xml D:音乐\\名称-标题\\ xxxx.xml
    • D:Music\\Name - Title\\artwork D:音乐\\名称-标题\\图稿
      • D:Music\\Name - Title\\artwork\\xxxx-type.jpg D:音乐\\名称-标题\\插图\\ xxxx-type.jpg

I have tried this: 我已经试过了:

for /d %%a in ("D:Music\Name - Title\*") do mkdir "%%~fa\artwork" 2>nul  

This creates new folders in 'Name Title' folders. 这将在“名称标题”文件夹中创建新文件夹。 But obviously won't move the files. 但显然不会移动文件。

I also tried this to create the folders and move the files: 我还尝试过此操作来创建文件夹并移动文件:

@echo off
    for /f "delims=" %%a D:Music\Name - Title\ ('dir /s/b/a-d *.* ^| find /i "*-type.jpg"') do (
    if not exist "%%~dpaartwork" md "%%~dpaartwork"
    move "%%~fa" "%%~dpaartwork")

The above does nothing. 上面什么都不做。 Any help is appreciated. 任何帮助表示赞赏。

Thanks 谢谢

Try this 尝试这个

@echo off& SetLocal
for /f "delims=" %%a in ('dir /ad /b "D:\Music\"') do (
    cd /d "%%~fa"
    if exist *-type.jpg (
        if not exist artwork md artwork
        move *-type.jpg artwork
    )
)

This will go through all folders directly in D:\\Music and if there are some *-type.jpg files in that folder, it will move them into subfolder artwork (which will be created if it does not exist). 这将直接遍历D:\\Music所有文件夹,并且如果该文件夹中有一些*-type.jpg文件,它将把它们移动到子文件夹artwork (如果不存在,将创建它们)。

If you have folders with *-type.jpg files also in subfolders, you can use this 如果子文件夹中也有带有*-type.jpg文件的文件夹,则可以使用此文件夹

@echo off& SetLocal
for /f "delims=" %%a in ('dir /ad /b /s "D:\Music\"') do (
    cd /d "%%~fa"
    if /i not "%%~na"=="artwork" if exist *-type.jpg (
        if not exist artwork md artwork
        move *-type.jpg artwork
    )
)

This should work: 这应该工作:

@echo off

for /R D:\Music %%F in (*-type.jpg) do (
   if not exist "%%~pFartwork" md "%%~pFartwork"
   move "%%F" "%%~pFartwork"
)

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

相关问题 Windows 7 Batch - 创建子文件夹,然后查找文件名中包含特定文本的文件并将这些文件移动到新创建的子文件夹中 - Windows 7 Batch - Create subfolder, then find files with certain text in file name and move those files in the newly created subfolder 批处理文件以在现有文件夹中创建子文件夹结构 - batch file to create subfolder structure within existing folders 比较两个文件夹及其子文件夹批处理文件 - Comparing Two Folders and its Subfolder batch file 创建批处理文件以删除,重命名和移动多个文件的多个子文件夹 - Create batch file to delete,rename and move multiple files multiple subfolder 批量创建文件夹和子文件夹 - Create folder and subfolder in batch 批处理文件以计算文件夹中的所有文件和子文件夹文件,并使用批处理文件以文件夹名称写入输出文件 - batch file to count all files in a folder and subfolder files and write output file in folder name using batch file 循环到子文件夹批处理文件重复相同的文件夹 - Looping to subfolder batch file repeats same folder 批处理文件以列出所有子文件夹路径 - Batch file to list all subfolder paths 如何通过批处理文件创建条件子文件夹? - How to Create Conditioned Subfolder through batch file? 从文件名的后缀创建子文件夹,然后移动文件 - Create subfolder from suffix of filename then move file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM