gpt4 book ai didi

powershell - 无法在递归复制期间排除文件夹

转载 作者:行者123 更新时间:2023-12-04 17:37:39 25 4
gpt4 key购买 nike

我是 powershell 的新手,在递归复制期间尝试排除某些目录时遇到了问题。任何帮助表示赞赏!
提前致谢。

$Date = Get-Date
$Date = $Date.adddays(-1)

$destPath = "\\destination\test"
$srcPath = "H:\program files\symphony\Save"
$srcPathRemits = “H:\program files\symphony\files"
$destDrive = "X:"
$User = "user"
$Password = "password"

$exclude = @('H:\program files\symphony\files\Temp\*','H:\program files\symphony\files\Other\*','H:\program files\symphony\files\etc\*','H:\program files\symphony\files\ParsedXML\*')

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive($destDrive, $destPath, $false, $User, $Password)

gci -recurse -path $srcPathRemits -Exclude $exclude | ? {!($_.psiscontainer) -AND $_.lastwritetime -gt $Date} | % { write-host $_.fullname; Copy-Item -path $_.fullname -destination $destDrive}
$net.RemoveNetworkDrive($destDrive,"true","true")

最佳答案

你没有说问题是什么,但我假设目录( $exclude )没有被正确排除。试试这个,对于 gci线:

Get-Item -Path H:\program files\symphony\files\* -Exclude Temp, Other, etc, ParsedXML | Get-ChildItem -recurse | ? {!($_.psiscontainer) -AND $_.lastwritetime -gt $Date} | %  { write-host $_.fullname; Copy-Item -path $_.fullname -destination $destDrive}

关于powershell - 无法在递归复制期间排除文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13353709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com