如何正确使用Copy-Item cmdlet? [英] How to use the Copy-Item cmdlet correctly?

查看:1251
本文介绍了如何正确使用Copy-Item cmdlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个小脚本,应将所有 .zip 文件复制到一个名为 F:\tempzip

I am building a small script which should copy all .zip files to a special folder called F:\tempzip.

我尝试使用 Copy- Item cmdlet,但我没有设法做到。脚本应该复制此文件夹中的所有文件(递归地)为.zip。

I tried it with Copy-Item cmdlet, but I didn't manage to do it. The script should copy all files from this folder (recursively) which are ".zip".

这是我所说的脚本的一部分:

This is the part of the script I am talking about:

get-childitem F:\Work\xxx\xxx\xxx -recurse | where {$_.extension -eq ".zip"} |

copy-item F:\tempzip

添加

推荐答案

当将项目管道到 copy-item 告诉F:\tempzip是目标路径。

When piping items to copy-item you need to tell it that "F:\tempzip" is the destination path.

| Copy-Item -Destination F:\tempzip

您还可以将管道连接到<$ c $通过使用 Get-ChildItem 的参数 -filter 运行

You can also cutout piping to the where operator by using Get-ChildItem's parameter -filter.

Get-Childitem "C:\imscript" -recurse -filter "*.zip" | Copy-Item -Destination "F:\tempzip"

编辑删除不必要的 foreach 循环和更新的说明。

Edit: Removal of unnecessary foreach loop and updated explanation.

这篇关于如何正确使用Copy-Item cmdlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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