简体   繁体   English

将子目录的所有内容复制到父目录的批处理脚本?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM