我怎样写一个批处理脚本复制一个目录到另一个,取代旧的文件? [英] How do I write a batch script that copies one directory to another, replaces old files?

查看:211
本文介绍了我怎样写一个批处理脚本复制一个目录到另一个,取代旧的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows批处理脚本,我可以一个目录复制到另一个。如果此目录已存在,然后为已存在于两个具有相同的名称和位置的每个文件,它应该被覆盖,如果它不存在,它应该只被添加

I'd like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the same name and location, it should be overwritten, if it does not exists, it should just be added.

在结束它应该是一个批处理脚本,我可以通过2个参数,源和放大器;目的地。

In the end it should be a batch script to which I can pass 2 arguments, source & destination.

推荐答案

在批处理文件中做到这一点。

In your batch file do this

set source=C:\Users\Habib\test
set destination=C:\Users\Habib\testdest\
xcopy %source% %destination% /y

如果您要复制的子目录的包括空目录,然后做的:

If you want to copy the sub directories including empty directories then do:

xcopy %source% %destination% /E /y

如果您只想复制子目录,而不是空的目录,然后使用 / S 这样的:

If you only want to copy sub directories and not empty directories then use /s like:

xcopy %source% %destination% /s /y

这篇关于我怎样写一个批处理脚本复制一个目录到另一个,取代旧的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆