Windows批处理文件:查找目录,如果不存在,创建,然后将文件以将其 [英] Windows Batch File: Look for directory, if not exist, create, then move file to it
问题描述
我想创建一个批处理文件或其他脚本,拿一个文件夹中的内容到另一个目录中包含其名称的文件夹。例如:
ShowName.Episode.Title.mkv应该被移动到\\电影\\ showname。如果\\电影\\ showname \\不存在,脚本将创建它。
有,平均10-15文件在将需要移动的时间。
任何想法?
感谢
@ECHO OFF
SETLOCAL
SETsourcedir = C:\\ sourcedir
SETDESTDIR = C:\\ DESTDIR
FOR / F令牌= 1-4delims =。 %%一个IN(
DIR / B / A-D%sourcedir%\\ *。*。*。MKV'
)DO(
MD%DESTDIR%\\ %%一个2 - ; NUL
MOVE%sourcedir%\\ %%一个%%湾%%角%% d的%DESTDIR%\\ %%一个\\
)
GOTO:EOF
这应该做你的动作。你不得不更改目录名,当然 - 不知道从哪里你的源目录,但目的地变得 \\你的情况的电影
可能是一个主意,试图 ECHO MOVE
第一,只是为了确保,此举是为要求的。
的 2 - ; NUL
在 MD
燮presses错误消息称该目录已经存在。
添加> NUL
到移动
行年底将坐席preSS的文件移动
消息。
I am trying to create a batch file, or other script, to take the contents of one folder to a folder containing its name in another directory. For example:
ShowName.Episode.Title.mkv should be moved to \movies\showname. if \movies\showname\ doesn't exist, the script would create it.
There are, on average, 10-15 files at a time that would need moved.
Any ideas?
Thanks
@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
FOR /f "tokens=1-4delims=." %%a IN (
'dir /b /a-d "%sourcedir%\*.*.*.mkv" '
) DO (
MD "%destdir%\%%a" 2>NUL
MOVE "%sourcedir%\%%a.%%b.%%c.%%d" "%destdir%\%%a\"
)
GOTO :EOF
This should do your moves. You'd have to change the directory names, of course - no idea where your source directory is, but destination becomes \movies
in your case.
May be an idea to try ECHO MOVE
first, just to make sure that the move is as-required.
The 2>nul
on the MD
suppresses the error messages saying the directory already exists.
Adding >nul
to the end of the MOVE
line will suppress the file moved
message.
这篇关于Windows批处理文件:查找目录,如果不存在,创建,然后将文件以将其的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!