당신이 (타사 .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 (누가 알았습니까 : P)에서 직접 DLL을 호출 할 수 있다는 것을 깨달았습니다. 그들은 또한 광범위한 문서를 가지고 있으며, 항상 더하기입니다. 나는 지금이 물건의 한가운데에있어. 그래서 비슷한 질문이 있으면 알려줘. –