2013-02-11 1 views

답변

2

당신은

$realeseDirectory 

목적지에 별도의 파일이나 폴더를 삭제하지

c:\releasedirectory\* 

Copy-item 같은 것이 있는지 확인해야하지만, 파일이 이미 존재하는 경우 -force으로는 owerwrite합니다

+0

안녕하세요 CB $ releaseDirectory = $ BuildFilePath + $ 프로젝트 이름 + "\"+ $ 프로젝트 이름 + "\ 빈 \"+ $의 compileMode + "\ _PublishedWebsites \"+ $ 프로젝트 이름 $ sitePath = "\\ $ strSvr \ c $ \ Shared \ WebSites "현재 대상의 파일을 삭제하고 있습니다. – user2062422

+0

@ user2062422 경로가 올바르게 빌드되었다고 말할 수는 없지만 소스의 모든 파일을 복사하려면 소스 경로의 끝에'\ *'를 추가해야합니다. 실제로 이상하게 작동합니다 ... 로컬에서 테스트합니다 일부 테스트 경로 ... 그리고 당신은 여분의 파일이 삭제 된 것을 볼 수 없을 것입니다 .. –

+0

Hello CB - 경로가 정확합니다. 현재 소스는 c : \ test \ file 1, file2이고 대상에는 c : \ shared \ website \ file1, file2 및 file3이 있습니다. 파일 1과 파일 2를 덮어 써야하며 파일 3을 유지해야합니다. 그것은 file1, file2를 덮어 쓰고 file3을 삭제하고 있습니다 – user2062422

1

귀하의 질문은 명확하지 않습니다. 따라서 약간 아래의 기능을 조정해야 할 수도 있습니다. 그런데 웹 사이트를 배포하려는 경우 디렉토리를 복사하는 것이 최선의 방법은 아닙니다.

function Copy-Directory 
{ 
    param (
     [parameter(Mandatory = $true)] [string] $source, 
     [parameter(Mandatory = $true)] [string] $destination   
    ) 

    try 
    { 
     Get-ChildItem -Path $source -Recurse -Force | 
      Where-Object { $_.psIsContainer } | 
      ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | 
      ForEach-Object { $null = New-Item -ItemType Container -Path $_ } 

     Get-ChildItem -Path $source -Recurse -Force | 
      Where-Object { -not $_.psIsContainer } | 
      Copy-Item -Force -Destination { $_.FullName -replace [regex]::Escape($source), $destination } 
    } 

    catch 
    { 
     Write-Error "$($MyInvocation.InvocationName): $_" 
    } 
} 

$releaseDirectory = $BuildFilePath + $ProjectName + "\" + $ProjectName + "\bin\" + $compileMode + "_PublishedWebsites\" + $ProjectName 
$sitePath = "\\$strSvr\c$\Shared\WebSites" 

Copy-Directory $releaseDirectory $sitePath 
+0

현재 소스에는 c : \ test \ file 1, file2가 있으며 대상에는 c : \ shared \ website \ file1, file2 및 file3이 있습니다. 파일 1과 파일 2를 덮어 써야하며 파일 3을 유지해야합니다. file1, file2 및 file3을 (를) 덮어 쓰는 중입니다. – user2062422

관련 문제