powershell局域网内同步多文件夹,文件脚本到固定文件夹
代码
#Source_Path是数组类型,其中保存的是需要备份的文件夹路径,即源路径。
$Source_Path="D:\Libary\Driver_state\v2\SX_driver_state_v1\src\UART_SPI_SC",
"D:\Libary\Driver_state\v2\CX_driver_state_v1\src\UART_SPI_CX",
"D:\Libary\Driver_state\v2\SPI\UART_SPI"
#DESTINATION_HOME中保存的是要备份到的文件夹路径,即目标路径。
$DESTINATION_HOME="\\192.168.7.190\LIB"
$Destination_Path=$DESTINATION_HOME #+"\"+(Get-Date).ToString("yyyyMMdd")
#检测目标路径是否存在,如果不存在则新建目标路径。
if (!(Test-Path -Path $Destination_Path))
{
New-Item -ItemType directory -Path $Destination_Path
}
#进行复制
foreach($Path in $Source_Path)
{
Copy-Item -Path $Path -Destination $Destination_Path -Recurse -Force
Write-Host "Source_Path:" $Path
Write-Host "Destination_Path:" $Destination_Path
}
Write-Host "Done!!!!"