我有一个C:\ CurrentProjects目录和一个C:\ HistoricProjects目录
列出了当前的项目目录 C:\ CurrentProjects \ LOCATIONNAME \ ProjectYear #### \ ProjectTitle \等...
我想搜索特定的项目年份,并将其及所有子文件夹移动到:
C:\ HistoricProjects \ LOCATIONNAME \等...
使用相同的位置名称而不移动任何其他项目年。
例如:
C:\ CurrentProjects \芝加哥\ ProjectYear2013 \等...
C:\ CurrentProjects \芝加哥\ ProjectYear2014 \等...
C:\ CurrentProjects \芝加哥\ ProjectYear2015 \等...
C:\ CurrentProjects \西雅图\ ProjectYear2013 \等...
C:\ CurrentProjects \西雅图\ ProjectYear2014 \等...
C:\ CurrentProjects \西雅图\ ProjectYear2015 \等...
VVVV
C:\ HistoricProjects \芝加哥\ ProjectYear2013 \等
C:\ HIstoricProjects \西雅图\ ProjectYear2013 \等
答案 0 :(得分:0)
在测试目录中尝试这样的事情:
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的等同于评论,但它对它们非常挑剔。注释不应该在代码块中使用(例如,在FOR
块内),如果您尝试使命令跨越多行(如第二个示例),则CMD将禁止。我只是用这种方式写它来帮助解释发生了什么。
这是您已经拥有的代码:
@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.
将它们结合起来,你的最终结果就像这样,但可能不是这样:
@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%\ )
P,这对我来说是一个学习过程。