首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用批处理将单个文件复制到子文件夹及其子文件夹,等等。

使用批处理将单个文件复制到子文件夹及其子文件夹,等等。
EN

Stack Overflow用户
提问于 2022-03-24 15:33:40
回答 3查看 418关注 0票数 0

我很好奇,一个必须执行的任务是否可以通过批处理来实现。我必须复制一个文件到多个子文件夹,其中也有子文件夹,文件也必须复制到。使用批处理,输入将如下所示:

代码语言:javascript
复制
@echo off
for /d %%a in ("C:\\Users\\thomas\\Desktop\\Battest\*.\*") do xcopy /y /d C:\\Users\\thomas\\Desktop\\Battest\\indextest.php "%%a"

这将只将index.php复制到第一个子文件夹中,该子文件夹直接位于下一个级别。

由于需要将index.php复制到700个文件夹中,而且我不知道所有具体的目录路径,所以我不知道如何使用通配符来处理这个问题,或者这个任务是否可以像这样完成。

我试图利用批处理将单个文件复制到多个子文件夹中,但路径我不知道。到目前为止,我只是设法将文件复制到第一个子文件夹中。

以下是显示方向结构的cmd输出。您可以看到,在每个文件夹中都有一个index.php,需要替换(我之前没有指定这一点)。对不起):

代码语言:javascript
复制
C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists>dir
 Datenträger in Laufwerk C: ist Windows
 Volumeseriennummer: 3C59-5A60

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:53    <DIR>          01_Sealing Guide
25.03.2022  07:54    <DIR>          02_Precast Concrete Plant Catalogue
25.03.2022  07:54    <DIR>          03_Structural and Civil Engineering Catalogue
25.03.2022  07:54    <DIR>          04_Price list
25.03.2022  07:54    <DIR>          05_Press Releases
25.03.2022  07:54    <DIR>          06_News
25.03.2022  07:54    <DIR>          07_Consulting Catalogue
23.03.2022  16:26             3.627 index.php
               1 Datei(en),          3.627 Bytes
               9 Verzeichnis(se), 343.890.636.800 Bytes frei

C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists>dir /s
 Datenträger in Laufwerk C: ist Windows
 Volumeseriennummer: 3C59-5A60

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:53    <DIR>          01_Sealing Guide
25.03.2022  07:54    <DIR>          02_Precast Concrete Plant Catalogue
25.03.2022  07:54    <DIR>          03_Structural and Civil Engineering Catalogue
25.03.2022  07:54    <DIR>          04_Price list
25.03.2022  07:54    <DIR>          05_Press Releases
25.03.2022  07:54    <DIR>          06_News
25.03.2022  07:54    <DIR>          07_Consulting Catalogue
23.03.2022  16:26             3.627 index.php
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
25.03.2022  07:53    <DIR>          English
25.03.2022  07:53    <DIR>          French
25.03.2022  07:53    <DIR>          German
23.03.2022  16:26             3.627 index.php
25.03.2022  07:53    <DIR>          Russian
25.03.2022  07:53    <DIR>          Spanish
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide\English

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
02.10.2020  14:14         2.393.613 BTi_Catalogue_Sealing Guide_EN_2020-09.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      2.395.719 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide\French

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
07.05.2021  08:53         2.997.413 BTi_Sealing Guide_FR_2020-09.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      2.999.519 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide\German

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
17.06.2021  09:27         2.872.797 BTi_Abdichtungsguide_DE_2020-09.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      2.874.903 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide\Russian

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
07.05.2021  08:42         3.039.947 BTi_Руководство по герметизации_RU_09-2020.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      3.042.053 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\01_Sealing Guide\Spanish

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
13.12.2021  11:34         3.560.598 BTi_Katalog_Abdichtung_ES_2021-12_web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      3.562.704 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:53    <DIR>          English
25.03.2022  07:53    <DIR>          French
25.03.2022  07:54    <DIR>          German
23.03.2022  16:26             3.627 index.php
25.03.2022  07:54    <DIR>          Polish
25.03.2022  07:54    <DIR>          Russian
25.03.2022  07:54    <DIR>          Spanish
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\English

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
07.10.2020  08:27         9.967.701 BTi_Catalogue_Precast Concrete Plant_EN_2020-09.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      9.969.807 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\French

25.03.2022  07:53    <DIR>          .
25.03.2022  07:53    <DIR>          ..
10.07.2020  15:01         9.737.367 BTi_Catalogue_Precast Concrete Plant_FR_2020_07.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      9.739.473 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\German

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
10.07.2020  12:34        10.145.406 BTi_Katalog_Betonfertigteilwerk_DE_2020-07.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     10.147.512 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\Polish

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
10.07.2020  15:35        10.116.783 BTi_Catalogue_Precast Concrete Plant_PL_2020-07.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     10.118.889 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\Russian

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
11.08.2020  07:53         5.882.519 BTi_Catalogue_Precast Concret Plant_RU_2020-07_web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      5.884.625 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\02_Precast Concrete Plant Catalogue\Spanish

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
10.07.2020  14:24         9.857.478 BTi_Catalogue_Structural and Civil Engineering_ES_2020-07.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      9.859.584 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:54    <DIR>          English
25.03.2022  07:54    <DIR>          French
25.03.2022  07:54    <DIR>          German
23.03.2022  16:26             3.627 index.php
25.03.2022  07:54    <DIR>          Russian
25.03.2022  07:54    <DIR>          Spanish
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue\English

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
26.07.2019  12:49         7.243.746 BTi_Catalogue_Structural and Civil Engineering_EN_2019-07.pdf
28.04.2021  15:43             2.106 index.php
11.12.2019  08:36               283 Web_Version.url
               3 Datei(en),      7.246.135 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue\French

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.09.2019  09:04         5.916.375 BTi_Catalogue_Structural and Civil Engineering_FR_2019-09.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      5.918.481 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue\German

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.07.2019  08:46         7.284.669 BTi_Katalog_Produktkatalog Hoch- und Tiefbau_DE_2019-07.pdf
16.11.2021  16:09        12.879.830 BTi_Katalog_Schalungstechnik_Syflex_DE_2021-11.pdf
28.04.2021  15:43             2.106 index.php
11.12.2019  08:34               267 Web-Version.url
               4 Datei(en),     20.166.872 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue\Russian

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
11.08.2020  07:54         3.245.824 BTi_Catalogue_Structural and Civil Engineering_RU_2019-11_web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      3.247.930 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\03_Structural and Civil Engineering Catalogue\Spanish

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
27.03.2020  13:00         7.493.352 BTi_Catalogue_Structural and Civil Engineering_ES_2020-03.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      7.495.458 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\04_Price list

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
23.03.2022  16:26             3.627 index.php
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:54    <DIR>          English
25.03.2022  07:54    <DIR>          French
25.03.2022  07:54    <DIR>          German
23.03.2022  16:26             3.627 index.php
25.03.2022  07:54    <DIR>          Russian
25.03.2022  07:54    <DIR>          Spanish
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases\English

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
26.04.2021  09:02        11.764.334 BTi_Press Kit_EN_2021-04.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     11.766.440 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases\French

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
26.04.2021  10:11         8.163.842 BTi_Dossier de presse_FR_2021-04.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      8.165.948 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases\German

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
30.03.2021  12:46           585.743 30 Jahre B.T innovation_de.pdf
04.03.2021  09:38        12.443.367 BTi_Pressemappe_DE_2021-03.pdf
28.04.2021  15:43             2.106 index.php
               3 Datei(en),     13.031.216 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases\Russian

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
26.04.2021  09:42         7.846.420 BTi_Press Kit_RU_2021-04.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      7.848.526 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\05_Press Releases\Spanish

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
26.04.2021  10:05         7.596.592 BTi_Kit de prensa_SP_2021-04.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),      7.598.698 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\06_News

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
08.06.2021  14:06           461.634 BTi_Important Information Regarding Prises and Offers 06-08-2021.pdf
23.03.2021  08:59           328.846 BTi_Price Increase for MultiForm starting 04-01-2021.pdf
23.03.2021  09:00           320.885 BTi_Price increase for shuttering magnets starting 05-01-2021.pdf
23.03.2022  16:26             3.627 index.php
07.03.2022  12:20           368.344 Price Increase BT-Spannschloss® (Turnbuckle) - BT innovation.pdf
31.01.2022  15:40           493.366 Price increase for RubberElast - BT innovation.pdf
25.01.2022  08:13           112.744 Price Increase GRP Products - BT innovation.pdf
               7 Datei(en),      2.089.446 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\07_Consulting Catalogue

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.03.2022  07:54    <DIR>          English
25.03.2022  07:54    <DIR>          German
23.03.2022  16:26             3.627 index.php
25.03.2022  07:54    <DIR>          Russian
               1 Datei(en),          3.627 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\07_Consulting Catalogue\English

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
24.11.2021  11:27        14.069.238 BTi_Catalogue_Consulting_EN_2021-10_web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     14.071.344 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\07_Consulting Catalogue\German

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.11.2021  13:37        14.651.703 BTi_Produktkatalog_consulting_DE_2021-10_Web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     14.653.809 Bytes

 Verzeichnis von C:\Users\thomasb\Desktop\01_General Catalogues and Price Lists\07_Consulting Catalogue\Russian

25.03.2022  07:54    <DIR>          .
25.03.2022  07:54    <DIR>          ..
25.11.2021  09:10        11.576.341 BTi_Catalogue_Consulting_RU_web.pdf
28.04.2021  15:43             2.106 index.php
               2 Datei(en),     11.578.447 Bytes

     Anzahl der angezeigten Dateien:
              66 Datei(en),    205.498.927 Bytes
              95 Verzeichnis(se), 343.888.109.568 Bytes frei
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-03-25 12:05:50

根据具体情况,有几种可能性:

  1. (重新)将文件indextest.php放置在根目录%UserProfile%\Desktop\Battest的直接子目录中:

对于/D %%J in (“%UserProfile%\\Desktop\Battest\*”) do (x拷贝/Y /D "%UserProfile%\Desktop\Battest\indextest.php“”%~J“)

  1. (重新)将文件indextest.php放置在根目录%UserProfile%\Desktop\Battest的大子目录中:

对于/D %%J in (“%UserProfile%\\Desktop\Battest\”) do ( /D %%I in (“%%~J”) do (x拷贝/Y /D "%UserProfile%\Desktop\Battest\indextest.php“”%~i“) )

  1. (Re-)Placing文件indextest.php在子目录和根目录%UserProfile%\Desktop\Battest的大子目录中:

对于/D %%J in (“%UserProfile%\\Desktop\Battest\”) do (x拷贝/Y /D "%UserProfile%\Desktop\Battest\indextest.php“”%~J“表示/D %%I in (%%~J) do (x拷贝/Y /D "%UserProfile%\Desktop\Battest\indextest.php”%%~i) )

  1. (Re-)Placing文件indextest.php在根目录%UserProfile%\Desktop\Battest的所有子目录中:

对于/D /R "%UserProfile%\Desktop\Battest“%J in (*) do (x拷贝/Y /D "%UserProfile%\Desktop\Battest\indextest.php”"%%~J“)

您可以将命令xcopy /Y /D替换为replace /U,以避免在尚未包含文件indextest.php的子目录中添加文件indextest.php

票数 0
EN

Stack Overflow用户

发布于 2022-03-24 15:42:29

你不能用forfiles做这个吗?类似于(未测试):

代码语言:javascript
复制
FORFILES /C "cmd /c if @isdir==TRUE xcopy /y /d C:\Users\...\indextest.php @path"
票数 0
EN

Stack Overflow用户

发布于 2022-03-24 20:10:47

代码语言:javascript
复制
for /r "C:\Users\thomas\Desktop\Battest" %%a in (.) do if /i "%%~dpa" neq "C:\Users\thomas\Desktop\Battest\" ECHO xcopy /y /d C:\Users\thomas\Desktop\Battest\indextest.php "%%a"

应该echo 的copy命令,在/r之后指定目录的每个子目录。

显然,在验证之后删除echo关键字以实际执行xcopy

有关详细信息,请参见提示符中的for /?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71605303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档