将 \\10.23.252.26\output\{文件夹名称} 下的所有文件(含子文件夹)复制到 \\10.23.252.26\output_wcc\{文件夹名称}。
核心规则:
.mpr 格式的同名文件不覆盖(跳过).mpr)复制 A221021 到 output_wcc
将 A221021 从 output 复制到 output_wcc
把 A221021 这个文件夹的东西复制过去
全部替换 A221021 到 output_wcc
强制复制 A221021 到 output_wcc
覆盖式复制 A221021
| 变量 | 值 |
|---|---|
| ------ | ----- |
| 源根路径 | \\10.23.252.26\output |
| 目标根路径 | \\10.23.252.26\output_wcc |
文件夹名称:由用户提供,AI 自动拼入路径。
param(
[string]$FolderName
)
$source = "\\10.23.252.26\output\$FolderName"
$target = "\\10.23.252.26\output_wcc\$FolderName"
if (-Not (Test-Path $source)) {
Write-Error "源文件夹不存在: $source"
exit 1
}
if (-Not (Test-Path $target)) {
New-Item -ItemType Directory -Path $target -Force | Out-Null
Write-Host "已创建目标文件夹: $target"
}
$files = Get-ChildItem -Path $source -File -Recurse
$total = $files.Count
$copied = 0
$skipped = 0
$skippedMpr = @()
$failed = 0
$failedFiles = @()
Write-Host ""
Write-Host "══════════════════════════════════════════"
Write-Host " 复制文件(.mpr 文件保护模式)"
Write-Host " 源目录: $source"
Write-Host " 目标目录: $target"
Write-Host " 文件总数: $total"
Write-Host "══════════════════════════════════════════"
Write-Host ""
foreach ($file in $files) {
$relativePath = $file.FullName.Substring($source.Length).TrimStart('\')
$destPath = Join-Path $target $relativePath
$destDir = Split-Path $destPath -Parent
if (-Not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
# .mpr 文件保护:同名 .mpr 存在则跳过
if ($file.Extension -eq '.mpr' -and (Test-Path $destPath)) {
$skipped++
$skippedMpr += $relativePath
Write-Host " [跳过] $relativePath (.mpr 保护)"
continue
}
try {
Copy-Item -Path $file.FullName -Destination $destPath -Force -ErrorAction Stop
$copied++
Write-Host " [复制] $relativePath"
} catch {
$failed++
$failedFiles += $file.FullName
Write-Host " [失败] $relativePath ($($_.Exception.Message))"
}
}
Write-Host ""
Write-Host "══════════════════════════════════════════"
Write-Host " 执行完成"
Write-Host " 复制成功: $copied / $total"
Write-Host " 跳过(.mpr): $skipped"
if ($skipped -gt 0) {
Write-Host " 被跳过的 .mpr 文件:"
$skippedMpr | ForEach-Object { Write-Host " - $_" }
}
if ($failed -gt 0) {
Write-Host " 失败: $failed"
$failedFiles | ForEach-Object { Write-Host " - $_" }
}
Write-Host "══════════════════════════════════════════"
param(
[string]$FolderName
)
$source = "\\10.23.252.26\output\$FolderName"
$target = "\\10.23.252.26\output_wcc\$FolderName"
if (-Not (Test-Path $source)) {
Write-Error "源文件夹不存在: $source"
exit 1
}
if (-Not (Test-Path $target)) {
New-Item -ItemType Directory -Path $target -Force | Out-Null
Write-Host "已创建目标文件夹: $target"
}
$files = Get-ChildItem -Path $source -File -Recurse
$total = $files.Count
$copied = 0
$failed = 0
$failedFiles = @()
Write-Host ""
Write-Host "══════════════════════════════════════════"
Write-Host " 复制文件(全部替换模式)"
Write-Host " 源目录: $source"
Write-Host " 目标目录: $target"
Write-Host " 文件总数: $total"
Write-Host "══════════════════════════════════════════"
Write-Host ""
foreach ($file in $files) {
$relativePath = $file.FullName.Substring($source.Length).TrimStart('\')
$destPath = Join-Path $target $relativePath
$destDir = Split-Path $destPath -Parent
if (-Not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
try {
Copy-Item -Path $file.FullName -Destination $destPath -Force -ErrorAction Stop
$copied++
Write-Host " [复制] $relativePath"
} catch {
$failed++
$failedFiles += $file.FullName
Write-Host " [失败] $relativePath ($($_.Exception.Message))"
}
}
Write-Host ""
Write-Host "══════════════════════════════════════════"
Write-Host " 执行完成"
Write-Host " 复制成功: $copied / $total"
if ($failed -gt 0) {
Write-Host " 失败: $failed"
$failedFiles | ForEach-Object { Write-Host " - $_" }
}
Write-Host "══════════════════════════════════════════"
A221021).mpr 文件,默认会被覆盖共 1 个版本