因此,我有两个独立的服务器,我需要同步具有相同名称但在不同目录结构中的目录。
例如,有一台服务器是\\calafs01\GFX_Drop\x\*
X是GFX_Drop中的任何目录,我希望复制它的所有子文件夹及其内容(仅限修改和新文件)
另一台服务器是\\calamedia\edit\y\x\*
Y是我们的用户使用的组织类别。
我需要把x上的任何东西拷贝到calamedia中,但是因为y,这使得操作变得非常困难。
我可以很容易地创建一个包含所有x值的数组:
$Projects = Get-ChildItem \\calafs01\GFX_Drop | %{$_.name}
但问题是让脚本在calamedia上找到要复制到的y目录中的目录x。
假设一旦我能弄清楚怎么做就使用机器复制...
提前感谢
EDIT per NAS答案:
所以我是个哑巴,我意识到在calamedia中x之后还有另一个目录,但它总是叫做GFX,所以目标路径实际上是\\calamedia\edit\y\x\GFX\*
假设这是一个简单的添加...因此,使用您的脚本并执行以下操作:
$get_y = Get-ChildItem -Directory -Path \\calamedia\edit | Get-ChildItem -Directory # get all dirs one level deeper
Get-ChildItem -Directory -Path \\calafs01\GFX_Drop\ | ForEach-Object { # get all folders 'x'
$dest_y = $get_y | Where-Object -Property Name -eq $_.Name # match folder names
if ($dest_y) {
Copy-Item -Path $_.FullName -Recurse -Destination "$dest_y.Parent.FullName/GFX" -Force -WhatIf
# or robocopy if you need to copy modified/new files only
}
}
基本上只是将/GFX
添加到$dest_y.Parent.FullName
的末尾(带引号),以为这会起作用,但现在它在目的地被绊倒了。展开目录时是否出现语法错误?
EDIT 2:
明白了。
PS C:\Users\chris.slagel> $get_y = Get-ChildItem -Directory -Path \\calamedia\edit | Get-ChildItem -Directory # get all dirs one level deeper
Get-ChildItem -Directory -Path \\calafs01\GFX_Drop\ | ForEach-Object { # get all folders 'x'
$dest_y = $get_y | Where-Object -Property Name -eq $_.Name # match folder names
if ($dest_y) {
Copy-Item -Path $_.FullName -Recurse -Destination "$($dest_y.Parent.FullName)\GFX" -Force -WhatIf
# or robocopy if you need to copy modified/new files only
}
}
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test Destination: \\calamedia\edit\Theatrical\GFX".
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test - Copy Destination: \\calamedia\edit\Gaming\GFX".
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test - Copy (2) Destination: \\calamedia\edit\Home Entertainment\GFX".
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test - Copy (3) Destination: \\calamedia\edit\Home Entertainment\GFX".
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test - Copy (4) Destination: \\calamedia\edit\TV & Streaming\GFX".
What if: Performing the operation "Copy Directory" on target "Item: \\calafs01\GFX_Drop\This Is A Test - Copy (5) Destination: \\calamedia\edit\VR\GFX".
看起来它正确地找到了类别文件夹,但是缺少了x部分(项目名称,在本例中是所有的"This is a test“文件夹)
例如,第一个目的地应该是\\calamedia\edit\Theatrical\This Is A Test\GFX
发布于 2018-09-28 05:25:12
$get_y = Get-ChildItem -Directory -Path \\calamedia\ | Get-ChildItem -Directory # get all dirs one level deeper
Get-ChildItem -Directory -Path \\calafs01\GFX_Drop\ | ForEach-Object { # get all folders 'x'
$dest_y = $get_y | Where-Object -Property Name -eq $_.Name # match folder names
if ($dest_y) {
Copy-Item -Path $_.FullName -Recurse -Destination $dest_y.Parent.FullName -Force -WhatIf
# or robocopy if you need to copy modified/new files only
}
}
https://stackoverflow.com/questions/52544847
复制相似问题