[英]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 我的目录看起来像这样
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: 新目录如下所示:
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.