powershell - 无法在递归复制期间排除文件夹 [英] powershell - unable to exclude folders during recursive copy
本文介绍了powershell - 无法在递归复制期间排除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 powershell 的新手,在递归复制期间尝试排除某些目录时遇到了问题.任何帮助表示赞赏!提前致谢.
I am new to powershell and am running into a problem while trying to exclude certain directories during recursive copy. Any help is appreciated! Thanks in advance.
$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
行:
You didn't say what the problem was, but I'll assume that the directories ($exclude
) were not properly excluded. Try this instead, for the gci
line:
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 - 无法在递归复制期间排除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文