更新时间:2023-12-05 18:34:04
尝试像这样在您的测试目录:
Try something like this in your testing directory:
FOR /D %d IN (*\ProjectYear2014\) DO (MOVE %d\ProjectYear2014\ C:\HistoricProjects\%d\ProjectYear2014 )
这是命令的基础是:
FOR /D %d IN :: for directories, store matches in variable %d
(*\ProjectYear2014\) :: that are located in (anything)\ProjectYear2014
DO (MOVE %d\ProjectYear2014\ :: Move target (match)\...
C:\HistoricProjects\%d\ProjectYear2014 ) :: To new directory ...
和我只是想解释:
是DOS相当于一个评论,但它是对他们非常挑剔。注释应该从来没有一个code座(比方说,一个的
块内)内使用,如果你试图让命令跨越多个线,如第二CMD将BARF例。我只是写这种方式来帮助解释了事情的原委。
And I just wanted to explain that ::
is the DOS equivalent of a comment, but it's extremely finicky about them. Comments should never be used inside a code block (say, inside a FOR
block), and CMD will barf if you try to make the command span multiple lines like second example. I just wrote it that way to help explain what was going on.
这是code你已经:
@echo off
Set /P YEAR=Project Year to move?
FOR %%A IN (ATTRIB C:\ActiveTest*\"ProjectYear %YEAR%") DO
::I can't figure out how to make DIR look back and only pull the 2nd level into a variable.
::If I can get that I figure I can work it into a ROBOCOPY somehow.
他们的结合,最终的结果将是这样的事情,但可能不会正是这一点:
Combining them, your final result will be something LIKE this, but probably not exactly this:
@echo off
Set /P YEAR=Project Year to move?
FOR /D %d IN (C:\CurrentProjects\*\ProjectYear%YEAR%\) DO (MOVE C:\CurrentProjects\%d\ProjectYear%YEAR%\ C:\HistoricProjects\%d\ProjectYear%YEAR%\ )
唷,这对我来说是一个学习的过程。
Phew, this was a learning process for me.