@@ -30,29 +30,30 @@ function Copy-Files {
3030 foreach ($file in $files ) {
3131 $status = " Copying file {0} of {1}: {2}" -f $counter , $files.Count , $file.Name
3232 Write-Progress - Activity " Copy disc image files" - Status $status - PercentComplete ($counter ++/ $files.count * 100 )
33- $restpath = $file.FullName -Replace $path , ' '
33+ $restpath = $file.FullName -Replace [ regex ]::Escape( $path ) , ' '
3434
3535 if ($file.PSIsContainer -eq $true ) {
36- Write-Debug " Creating $ ( $destination + $restpath ) "
37- New-Item ($destination + $restpath ) - Force:$force - Type Directory - ErrorAction SilentlyContinue
36+ $targetPath = Join-Path $destination $restpath
37+ Write-Debug " Creating $targetPath "
38+ New-Item $targetPath - Force:$force - Type Directory - ErrorAction SilentlyContinue
3839 } else {
39- Write-Debug " Copy from $ ( $file.FullName ) to $ ( $destination + $restpath ) "
40+ $targetPath = Join-Path $destination $restpath
41+ Write-Debug " Copy from $ ( $file.FullName ) to $targetPath "
4042 try {
41- Copy-Item $file.FullName ($destination + $restpath ) - ErrorAction Stop - Force:$force
42-
43+ Copy-Item $file.FullName $targetPath - ErrorAction Stop - Force:$force
4344
4445 # Remove ReadOnly attribute using attrib for consistency
45- & attrib - R ( $destination + $restpath ) 2> $null
46+ & attrib - R $targetPath 2> $null
4647
4748 # Force garbage collection to release file handles
4849 $copiedFile = $null
4950 } catch {
5051 Write-Debug " Failed to copy $ ( $file.FullName ) : $ ( $_.Exception.Message ) "
5152 # Try alternative method if standard copy fails
5253 try {
53- [System.IO.File ]::Copy($file.FullName , ( $destination + $restpath ) , $force )
54+ [System.IO.File ]::Copy($file.FullName , $targetPath , $force )
5455 # Remove ReadOnly attribute using attrib for consistency
55- & attrib - R ($destination + $restpath ) 2> $null
56+ & attrib - R ($destination \ $restpath ) 2> $null
5657 } catch {
5758 Write-Debug " Alternative copy method also failed: $ ( $_.Exception.Message ) "
5859 }
0 commit comments