复制文件而不覆盖 [英] Copy files without overwrite

查看:82
本文介绍了复制文件而不覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在命令行上找到一种方法来说将所有文件从目录 A 复制到目录 B,但如果该文件已存在于目录 B 中,请不要覆盖它,无论哪个文件较新,不要提示我."

我经历过复制、移动、xcopy 和robocopy,我能得到的最接近的是你可以告诉 robocopy将 A 复制到 B,但不要用旧文件覆盖新文件",但这对我不起作用.我查看了 xxcopy,但放弃了它,因为我不希望第三方依赖 Visual Studio 构建后事件,这将需要其他 SVN 用户安装该工具才能进行构建.

我想向 Visual Studio 2010 中的构建后事件添加命令行,以便从 T4 模板用于新的 EF 模型对象被分发到它们所属的项目文件夹,但为现有对象重新生成的文件不会覆盖可能已编辑的目标文件.

由于 T4 模板重新生成,源文件总是更新的,我认为不能可靠地使用更新"开关.

对于那些我可以使用的项目,我使用部分类,但我生成的其他内容不能使用部分类(例如,生成默认的 EditorTemplate 或 DisplayTemplate *.ascx 文件).

有人解决过类似的问题吗?

解决方案

For %F In ("C:From*.*") Do If Not Exist "C:To\%~nxF"复制 "%F" "C:To\%~nxF"

I just can't seem to find a way on the command line to say "copy all the files from directory A to directory B, but if the file already exists in directory B, don't overwrite it, no matter which file is newer, and don't prompt me."

I have been through copy, move, xcopy & robocopy, and the closest I can get is that you can tell robocopy "copy A to B, but don't overwrite newer files with older files," but that doesn't work for me. I looked at xxcopy, but discarded it, as I don't want to have a third-party dependency on a Visual Studio post-build event that will require other SVN users to have that tool installed in order to do the build.

I want to add a command line to the post-build event in Visual Studio 2010 so that the files that are generated from the T4 templates for new EF model objects get distributed to the project folders to which they belong, but regenerated files for existing objects don't overwrite potentially edited destination files.

Since the T4 template regenerates, the source file is always newer, and I can't use the "newer" switch reliably, I don't think.

I use partial classes for those items for which I can, but there are other things I generate that can't use partial classes (e.g. generating a default EditorTemplate or DisplayTemplate *.ascx file).

Any one have any similar problems they have solved?

解决方案

For %F In ("C:From*.*") Do If Not Exist "C:To\%~nxF" Copy "%F" "C:To\%~nxF"

这篇关于复制文件而不覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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