我有一个从$sourceto复制文件的 powershell 脚本,$dest它排除了某些文件类型。它可以很好地排除我的 csv 文件和 web.config 文件,但不会排除日志文件夹的内容。这是我的脚本,排除文件内容而不是Log文件夹本身的正确语法是什么?
$exclude = @('Thumbs.db','*-Log.csv','web.config','Logs/*')
Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}
Run Code Online (Sandbox Code Playgroud)
您需要使用要避免的路径设置第二个数组,然后在管道中添加过滤器。这是一些示例代码:
$exclude = @('Thumbs.db','*-Log.csv','web.config','Logs/*')
$directory = @("C:\logs")
Get-ChildItem $source -Recurse -Exclude $exclude | where {$directory -notcontains $_.DirectoryName}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23966 次 |
| 最近记录: |