简体   繁体   English

批处理:创建文件夹列表,然后将多个文件/文件夹复制到所有文件夹中

[英]Batch: Create a list of folders and then copy multiple files/folders into all of them

I am a CAD manager in need of some help. 我是需要一些帮助的CAD经理。 I am no programmer, but I have a very basic understanding of DOS commands so I thought I could use XCOPY to do this, but I don't know how. 我不是程序员,但是我对DOS命令有非常基本的了解,所以我认为我可以使用XCOPY来做到这一点,但是我不知道该怎么做。

I have a folder, under which are hundreds of subfolders that change with time (each employee has one folder) so maintaining a manual listing (as I have been doing) is not easy. 我有一个文件夹,该文件夹下有数百个随时间变化的子文件夹(每个员工都有一个文件夹),因此要维护一个手动列表(就像我一直在做的那样)并不容易。 I also have a _TEMPLATE subfolder that contains several files and folders. 我还有一个_TEMPLATE子文件夹,其中包含几个文件和文件夹。

I would like to copy the contents of the _TEMPLATE folder into all the other subfolders, overwriting all existing files and creating all non-existing folders. 我想将_TEMPLATE文件夹的内容复制到所有其他子文件夹中,覆盖所有现有文件并创建所有不存在的文件夹。

From what I've seen with some searching in here it seems to pretty easy to accomplish these two tasks (to create the list of folders and to copy into a list of folders) but I'm just too dumb to understand how to combine the two into one file :) 从我在这里进行的一些搜索所看到的,完成这两个任务(创建文件夹列表并将其复制到文件夹列表中)似乎非常容易,但是我太笨拙了,无法理解如何结合使用两合一文件:)

EDIT : 编辑:

Well, I've found a PowerShell script that does what I need perfectly. 好吧,我找到了一个PowerShell脚本,可以完美满足我的需求。 Since I managed to run the PowerShell I guess my problem is solved :D 由于我设法运行了PowerShell,所以我想我的问题已经解决了:D

$folder = Get-Childitem -name -exclude *.*,_TEMPLATE
foreach ($f in $folder)
    {xcopy "_TEMPLATE\*.*" "$f" /e /r /y }

Thanks for all the fish ;) 感谢所有的鱼;)

Try this: 尝试这个:

@echo off &setlocal
cd /d "RootFolder=X:\folder\to\my data"
for /d %%a in (*) do xcopy "_TEMPLATE" "%%~fa" /sihrky

For xcopy options see xcopy /? 有关xcopy选项,请参见xcopy /? , to test the command without writing add option /l . ,以在不编写添加选项/l情况下测试命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM