如果项目尚不存在,则将项目从源复制到目标 [英] Copy items from Source to Destination if they don't already exist

查看:46
本文介绍了如果项目尚不存在,则将项目从源复制到目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的 powershell 复制脚本,可以将项目从源文件夹复制到目标文件夹.但是,这移动了太多数据,我想检查文件名是否已经存在,以便可以忽略该文件.我不需要像验证创建日期/校验和等那样复杂.

I have a pretty basic powershell copy script that copies items from a source folder to a destination folder. However this is moving way too much data, and I'd like to check if the filename already exists so that file can be ignored. I don't need this as complex as verifying created date/checksum/etc.

目前是这样的:

Copy-Item source destination -recurse
Copy-Item source2 destination2 -recurse

我想我需要添加 Test-Path cmdlet,但我不确定如何实现它.

I'd imagine I need to add the Test-Path cmdlet, but I'm uncertain how to implement it.

推荐答案

为此,您始终可以从 PowerShell 调用 ROBOCOPY.

You could always call ROBOCOPY from PowerShell for this.

使用/xc(排除已更改)/xn(排除较新)和/xo(排除较旧)标志:

Use the /xc (exclude changed) /xn (exclude newer) and /xo (exclude older) flags:

robocopy /xc /xn /xo source destination 

这只会复制那些不在目标文件夹中的文件.

This will ONLY copy those files that are not in the destination folder.

更多选项输入robocopy/?

这篇关于如果项目尚不存在,则将项目从源复制到目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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