将特定文件批量复制到所有目录和子目录(Batch copy a specific file to all directories and subdirectories)

编程入门 行业动态 更新时间:2024-10-27 13:27:12
将特定文件批量复制到所有目录和子目录(Batch copy a specific file to all directories and subdirectories)

我在c:\ folders目录中有一个文件夹,其中大约6000个子文件夹以不同的编号命名,每个子文件夹还有2个子文件夹,名为“medium”和“thumbs”。

我需要将位于c:\ folders中的名为index.html的文件复制到所有6000个文件夹中,并复制到6000个文件夹中每个文件夹的所有介质和拇指子文件夹中。

我正在尝试构建一些像这样的批处理代码

for /D %%D in ("C:\folders\*.*") do ( pushd "%%~D" copy "index.html" copy "index.html" "medium\" copy "index.html" "thumbs\" popd )

但这不起作用。 我究竟做错了什么?

i have a folder in c:\folders directory with around 6000 subfolders named with different numbers and each subfolder has 2 more subfolders called "medium" and "thumbs".

I need to copy a file called index.html which is located in c:\folders into ALL 6000 folders and into all medium and thumbs subfolders of each one of the 6000 folders.

I am trying to build some batch code like this

for /D %%D in ("C:\folders\*.*") do ( pushd "%%~D" copy "index.html" copy "index.html" "medium\" copy "index.html" "thumbs\" popd )

but this is not working. What am I doing wrong?

最满意答案

如果它适用于每个子文件夹,这应该可以完成

set "source=full path of index.html" for /f "delims=" %%D in ('dir /b /s /ad "C:\folders\*") do ( copy "%source%" "%%~D" )

编辑: 在copy命令行中禁止控制台add >nul中的输出 要不覆盖index.html文件,请用echo n|copy /-y替换copy

set "source=full path of index.html" for /f "delims=" %%D in ('dir /b /s /ad "C:\folders\*") do ( echo n|copy /-y "%source%" "%%~D">nul )

http://ss64.com/nt/copy.html

This should do the job if it's for every subfolder

set "source=full path of index.html" for /f "delims=" %%D in ('dir /b /s /ad "C:\folders\*") do ( copy "%source%" "%%~D" )

edit: to suppress output in console add >nul in copy command line to not overwrite index.html files, replace copy by echo n|copy /-y

set "source=full path of index.html" for /f "delims=" %%D in ('dir /b /s /ad "C:\folders\*") do ( echo n|copy /-y "%source%" "%%~D">nul )

http://ss64.com/nt/copy.html

更多推荐

folders,文件夹,thumbs,html,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-07-22 07:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子目录   文件批量   目录   Batch   copy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!