我很好奇是否可以通過使用批處理來完成必須執行的任務。我必須將單個檔案復制到多個子檔案夾中,這些子檔案夾也有檔案必須復制到的子檔案夾。使用批處理,輸入看起來像這樣:
@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 需要替換(我之前沒有指定。抱歉):
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
uj5u.com熱心網友回復:
根據具體情況,有幾種可能性:
(重新)將檔案
indextest.php放在根目錄的直接子目錄中%UserProfile%\Desktop\Battest:for /D %%J in ("%UserProfile%\Desktop\Battest\*") do ( xcopy /Y /D "%UserProfile%\Desktop\Battest\indextest.php" "%%~J" )(重新)將檔案
indextest.php放在根目錄的孫子中%UserProfile%\Desktop\Battest:for /D %%J in ("%UserProfile%\Desktop\Battest\*") do ( for /D %%I in ("%%~J\*") do ( xcopy /Y /D "%UserProfile%\Desktop\Battest\indextest.php" "%%~I" ) )(重新)將檔案
indextest.php放在根目錄的子孫目錄中%UserProfile%\Desktop\Battest:for /D %%J in ("%UserProfile%\Desktop\Battest\*") do ( xcopy /Y /D "%UserProfile%\Desktop\Battest\indextest.php" "%%~J" for /D %%I in ("%%~J\*") do ( xcopy /Y /D "%UserProfile%\Desktop\Battest\indextest.php" "%%~I" ) )(重新)將檔案
indextest.php放在根目錄的所有后代中%UserProfile%\Desktop\Battest:for /D /R "%UserProfile%\Desktop\Battest" %%J in (*) do ( xcopy /Y /D "%UserProfile%\Desktop\Battest\indextest.php" "%%~J" )
您可以將命令替換為xcopy /Y /D,replace /U以避免indextest.php在尚未包含此類的子目錄中添加檔案。
uj5u.com熱心網友回復:
你不能這樣做forfiles嗎?類似的東西(未測驗):
FORFILES /C "cmd /c if @isdir==TRUE xcopy /y /d C:\Users\...\indextest.php @path"
uj5u.com熱心網友回復:
所以我在這里嘗試了這個(v4 @aschipfl):
for /D /R "%UserProfile%\Desktop\01_General Catalogues and Price Lists" %%J in (*) do (replace /S "%UserProfile%\Desktop\01_General Catalogues and Price Lists\index.php" "%%~J")
對于我的實際專案,它有效!謝謝@aschipl 和其他人!
uj5u.com熱心網友回復:
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為每個子目錄指定的目錄的復制命令在/r.
很明顯,驗證后去掉echo關鍵字才能真正執行xcopy.
有關詳細資訊,請參閱for /?提示。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/451386.html
標籤:批处理文件
上一篇:受信任的發布者證書安裝
