[英]How to robocopy using regex matched folder from one server to another
我有一個使用robocopy將文件從一個系統復制到我們的服務器以及特定路徑的構建系統。 在引入新要求之前,以下方法一直有效:
robocopy local\dist \\server01\somepath\dist XF *.* /E
現在,我們要更改名稱以包含構建信息。 例如,“ dist1”,“ dist2”,“ distabcd”。 無論如何,重點是文件夾名稱正在更改。 如何告訴robocopy匹配以'dist'開頭的任何名稱,但復制到遠程服務器上正確的完整命名dist文件夾
robocopy local\dist* \\server01\somepath\[????] XF *.* /E
我可以選擇使用PowerShell命令來執行此操作,假設它可以復制到服務器位置。 我對PowerShell幾乎一無所知,但歡迎任何提示。
Powershell通過“ -match”和“ -contains”運算符提供RegEx功能。 以下是捕獲更改目錄的示例:
$localDirectory = "local\dist"
$directory = "\\server01\somepath\dist"
$keyword = "dist"
$fileDirectory = Get-ChildItem -Path $directory -Recurse
foreach ($container in $fileDirectory)
{
# -match is one of the RegEx functions we may utilize for this operation
# e.g dist1.. dist2.. distabc.. adist.. mynewdistrubition
if ($container -match $keyword)
{
try
{
Copy-Item -Path "$($directory)\$($container)" -Destination $localDirectory -Force -Recurse
}
catch [System.Exception]
{
Write-Output $_.Exception
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.