あなたは(サードパーティの.NETモジュールで:P)ネイティブPowerShellを使用したい場合や、長いファイルパスをさせたくない(> 255文字)が停止コピー、あなたはこれを使用することができます。
# Import AlphaFS .NET module - http://alphafs.codeplex.com/
Import-Module C:\Path\To\AlphaFS\DLL\AlphaFS.dll
# Variables
$SourcePath = "C:\Temp"
$DestPath = "C:\Test"
# RecursePath function.
Function RecursePath([string]$SourcePath, [string]$DestPath){
# for each subdirectory in the current directory..
[Alphaleonis.Win32.Filesystem.Directory]::GetDirectories($SourcePath) | % {
$ShortDirectory = $_
$LongDirectory = [Alphaleonis.Win32.Filesystem.Path]::GetLongPath($ShortDirectory)
# Create the directory on the destination path.
[Alphaleonis.Win32.Filesystem.Directory]::CreateDirectory($LongDirectory.Replace($SourcePath, $DestPath))
# For each file in the current directory..
[Alphaleonis.Win32.Filesystem.Directory]::GetFiles($ShortDirectory) | % {
$ShortFile = $_
$LongFile = [Alphaleonis.Win32.Filesystem.Path]::GetLongPath($ShortFile)
# Copy the file to the destination path.
[Alphaleonis.Win32.Filesystem.File]::Copy($LongFile, $LongFile.Replace($SourcePath, $DestPath), $true)
}
# Loop.
RecursePath $ShortDirectory $DestPath
}
}
# Execute!
RecursePath $SourcePath $DestPath
このコードは私の非常に大きなプロジェクトからストリッピングが、私はそれを簡単なテストを与え、動作するように思われましたのでご注意ください。お役に立てれば!
あなたが言及したライブラリはいいようです:http://alphafs.codeplex.com/ –
徹底的な答えをありがとう。私はM $に対する信仰を失っています。ばかげてる。私はxcopyに固執します。シンプルで簡潔で、機能します。 Powershellはthedailywtfに属します。 – Jim
ええ、AlphaFSプロジェクトは優れています。私たちは、グループ共有上に長いファイルパスを持つ、私たちの環境に大きな問題を抱えています。最初はネイティブのC#コードを書いていましたが、PowerShellから直接DLLを呼び出すことができました(Pは知っていました)。彼らには広範な文書もありますが、これは常にプラスです。私はこの物事の真っ只中にいるので、もしあなたに似たような質問があれば教えてください。 –