2010-09-08 135 views
0

我檢查了使用Google Checkout,WorkingCopy一個項目的工作副本,然後再使用清理-WorkingCopy刪除目錄(這些函數的代碼是在這篇文章的末尾)。怪異的行爲

問題,我面對:

  1. 相反呼應"Checking out from svn://somePath1 to C:/somePath2"呼應"Checking out from svn://somePath1 C:/somePath2 to"
  2. 在清理-WorkingCopy,它拋出,而試圖執行Pushd以下錯誤的,

     
    <Push-Location : Cannot convert 'System.Object[]' to the type 'System.String' 
    required by parameter 'LiteralPath'. Specified method is not supported. 
        + Pushd <<<< $directory 
        + CategoryInfo : InvalidArgument: (:) [Push-Location], ParameterBindingException 
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.PushLocationCommand>

  3. 最後,我得到的錯誤"The syntax of the command is incorrect"在執行Rmdir

我使用的功能如下。我檢查了發送給函數的參數,它們是正確的。

#Checks out a copy from svnPath into appFilePath 
Function Checkout-WorkingCopy($svnPath, $appFilePath) { 

    Echo "Checking out from $svnPath to $appFilePath" 

    svn checkout $svnPath $appFilePath --quiet 

    Echo "Checkout Done" 
} 

#Deletes the working copy previously checked out 
Function Cleanup-WorkingCopy($directory, $appFilePath) { 

    Pushd $directory 
    Cmd /C "Rmdir /S /Q $appFilePath" 
} 

回答

3

它看起來像$目錄是geting通過一個值的數組。當你需要調試這樣的東西,嘗試檢查傳入的值同樣,而不是掏出來的cmd.exe只使用PowerShell的刪除,項目的cmdlet:。

Function Cleanup-WorkingCopy($directory, $appFilePath) { 
    $directory | Foreach {"$($_.GetType().Fullname): $_" } 
    Pushd $directory 
    Remove-Item $appFilePath -Recurse -Force 
} 

其實這種方法你不需要$目錄完全可以用以下方式代替整個功能:

Remove-Item $appFilePath -Recurse -Force 
+0

你說得對。 $ directory是2個字符串的數組(1)目錄的路徑(2)appFile的路徑。但無處代碼我在做任何這樣的操作,除了$ appFilePath =聯接路徑-Path $目錄-ChildPath「AppFile」。難道我做錯了什麼? – Rahul 2010-09-08 18:54:01

+0

這恰好與我的第一個問題一樣。 $ svnPath是2個字符串的數組,實際的svnPath和appFilePath。讓我想知道函數是否接受數組中的所有參數:| – Rahul 2010-09-08 19:03:00

+0

一個簡單的谷歌搜索帶我去http://weblogs.asp.net/soever/archive/2006/11/29/powershell-calling-a-function-with-parameters.aspx其中有如何調用一個整潔的解釋與參數 – Rahul 2010-09-08 19:06:26