Bat複製目錄到多個文件夾下

定義路徑,放在一個 mypath.txt 中。

D:\apache-tomcat-8.5.39\webapps\aaa\
D:\apache-tomcat-8.5.39\webapps\bbb\
D:\apache-tomcat-8.5.39\webapps\ccc\
D:\apache-tomcat-8.5.39\webapps\ddd\

遍歷上面的txt,取出每一行來拼出目錄路徑。執行復制:

@echo off
@setlocal enabledelayedexpansion

REM 這裏是原文件路徑
set sourcePath=E:\myweb\

REM 遍歷txt文件取目標路徑
@for /f "delims=" %%i in (mypath.txt) do (
	
	@set targetPath=%%i
	
	::如果文件夾存在,先刪除
	if exist !targetPath! rd /s/q !targetPath!

	::創建文件夾
	md !targetPath!

	::複製文件 index.html
	if exist "!targetPath!index.html" del /y "!targetPath!index.html"
	@echo f | xcopy "%sourcePath%"index.html !targetPath! /y

	::複製文件夾 html
	if not exist "!targetPath!html" md "!targetPath!html"
	echo d | xcopy "%sourcePath%html" "!targetPath!html" /c/q/e/y

	::複製文件夾 resources
	if not exist "!targetPath!resources" md "!targetPath!resources"
	echo d | xcopy "%sourcePath%resources" "!targetPath!resources" /c/q/e/y
)

pause
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章