用于将文件复制到具有条件的所有子文件夹的批处理文件 [英] Batch file to copy a file into all subfolders with a condition
问题描述
我需要一个简单批处理文件的语法,该文件将文件从根文件夹复制到以前缀开头的所有子文件夹(非递归)。
例如:我需要带有for循环的批处理文件 c:\ MyRy \CopyCfgToSubs.bat
这会将文件 c:\ MyRy \ My.config
复制到每个子文件夹中:
c:\ MyRoot \Mysub1 \
c:\ MyRoot \Mysub2 \
。
。
。
c:\ MyRoot\MysubN \
[sup]
I need the syntax of a simple batch file that will copy a file from a root folder to all subfolders (not recursive) that start with a prefix.
E.g.: I need the batch file c:\MyRoot\CopyCfgToSubs.bat
with a for loop that will copy the file c:\MyRoot\My.config
into each of the sub folders:
c:\MyRoot\Mysub1\
c:\MyRoot\Mysub2\
.
.
.
c:\MyRoot\MysubN\
[sup]
// What have I tried?
我'我们遇到了这个代码示例:
I've come across this code sample:
for /r "C:\MyRoot" %%f in (.) do (
copy "C:\MyRoot\a.config" "%%~ff" > nul
)
这是80%,我需要的另外就是如何只复制到第一级子文件夹,并且仅限于那些以MySub开头的子文件夹
[ / sup]
Which is 80%, what I need in addition is how to copy to the 1st level of subfolders only, AND only to those subfolders that start with "MySub"
[/sup]
推荐答案
在CMD中,它类似于:
In CMD it's Something like:
cd \MyRoot
for /D %x in (MySub*) do copy a.config %x
并在批处理文件中:
and inside a batch file:
cd \MyRoot
for /D %%x in (MySub*) do copy a.config %%x
这篇关于用于将文件复制到具有条件的所有子文件夹的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!