[英]Batch script that copies all contents of subdirectories into a parent directory?
Let's say I have a batch file, script.bat. 假设我有一个批处理文件script.bat。 This batch file is placed into a parent folder.
该批处理文件放置在父文件夹中。
> Parent folder
script.bat
> subdirectory1
file1.1
file1.2
file1.3
> subdirectory2
file2.1
file2.2
file2.3
How do I write the batch file so that when I double click on it, it copies all the files from (inside the subdirectories) to (the folder that the batch file is located in)? 如何编写批处理文件,以便在双击它时将所有文件从(在子目录内)复制到(该批处理文件所在的文件夹)?
The code you're looking for is 您正在寻找的代码是
for /d %%I in (*) do copy "%%~I\*" .
for
performs the command after do
on every directory (because of the /d
switch) matched by *
. for
在由*
匹配的每个目录(由于/d
开关)上执行do
之后执行命令。 copy
copies. copy
副本。 %%~I
is a variable with a value of whatever directory name to which the for
loop has progressed. %%~I
是一个变量,其值等于for
循环所经过的目录名称。 The tilde in %%~I
strips surrounding quotation marks, if any. %%~I
〜I中的波浪号会%%~I
周围的引号(如果有)。 The .
的
.
at the end is shorthand for the current working directory (the directory containing the batch script). 最后是当前工作目录(包含批处理脚本的目录)的简写。 See
for /?
看到
for /?
in a cmd console for more info. 在cmd控制台中获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.