问题描述
我有一个C:\\ CurrentProjects目录和C:\\目录HistoricProjects
I have a C:\CurrentProjects directory and a C:\HistoricProjects directory
目前的项目目录布局
C:\\ CurrentProjects \\ LOCATIONNAME \\ ProjectYear #### \\ ProjectTitle \\等...
The current projects directory is laid out C:\CurrentProjects\LocationName\ProjectYear####\ProjectTitle\etc...
我愿做一个搜索一个具体项目年度和下的移动和所有子文件夹:
I would like to do a search of a specific Project Year and move it and all subfolders under to the:
C:\\ HistoricProjects \\ LOCATIONNAME \\等...
C:\HistoricProjects\LocationName\etc...
有没有移动任何其他项目中使用多年的同一位置的名称。
with the same location name used without moving any other project years.
因此,例如:
C:\\ CurrentProjects \\芝加哥\\ ProjectYear2013 \\等等...
C:\\ CurrentProjects \\芝加哥\\ ProjectYear2014 \\等...
C:\CurrentProjects\Chicago\ProjectYear2014\etc...
C:\\ CurrentProjects \\芝加哥\\ ProjectYear2015 \\等...
C:\CurrentProjects\Chicago\ProjectYear2015\etc...
C:\\ CurrentProjects \\西雅图\\ ProjectYear2013 \\等等...
C:\\ CurrentProjects \\西雅图\\ ProjectYear2014 \\等...
C:\CurrentProjects\Seattle\ProjectYear2014\etc...
C:\\ CurrentProjects \\西雅图\\ ProjectYear2015 \\等...
C:\CurrentProjects\Seattle\ProjectYear2015\etc...
VVVV
C:\\ HistoricProjects \\芝加哥\\ ProjectYear2013 \\等。
C:\HistoricProjects\Chicago\ProjectYear2013\etc..
C:\\ HIstoricProjects \\西雅图\\ ProjectYear2013 \\等。
C:\HIstoricProjects\Seattle\ProjectYear2013\etc..
推荐答案
尝试像这样在您的测试目录:
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.
这篇关于批处理脚本根据当前父名特定子文件夹移动到新的父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!