将文件复制到每个文件夹及其子文件夹中 [英] Copy a file into every folder and its subfolders
本文介绍了将文件复制到每个文件夹及其子文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
"Here I am"-folder
|
|--- mainfolder 1
| |
| |--- subfolder 1
| |--- subfolder 2
|
|--- mainfolder 2
| |
| |--- subfolder 1
| |--- subfolder 2
我想将一个批处理文件放入Here I am"文件夹并从那里执行它.它应该将名为 text.txt 的文件复制到所有主文件夹及其子文件夹中.
I want to place a batch-file into the "Here I am"-folder and execute it from there. It should copy a file named text.txt into all mainfolders and into their subfolders.
推荐答案
使用以下脚本:
@echo off
for /r "%CD%" %%f in (.) do (
copy "Text.txt" "%%~ff" > nul
)
来源:https://stackoverflow.com/a/1321539/1756941
@echo off
Setlocal EnableDelayedExpansion
cls
set currentDirectory=%CD%
FOR /D %%g IN ("*") DO (
Pushd %CD%\%%g
FOR /D %%f IN ("*") DO (
copy "%currentDirectory%\Text.txt" "%%~ff"
)
Popd
)
pause
这篇关于将文件复制到每个文件夹及其子文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文