programing

PowerShell에서 복사할 파일 목록을 가져옵니다.

subpage 2023. 8. 12. 10:19
반응형

PowerShell에서 복사할 파일 목록을 가져옵니다.

PowerShell을 사용하고 있습니다.Copy-Item파일이 있는 디렉터리를 다른 위치에 복사하는 명령입니다.

복사 명령의 상태를 알 수 있도록 복사되는 콘솔의 모든 파일을 표시합니다.

콘솔에서 보기를 원하는 경우-verbose스위치:

copy-item -path $from -destination $to -verbose

파일 또는 디렉터리 목록을 가져오려는 경우:

$files = copy-item -path $from -destination $to -passthru | ?{$_ -is [system.io.fileinfo]}
$source=ls c:\temp *.*
$i=1
$source| %{
    [int]$percent = $i / $source.count * 100
    Write-Progress -Activity "Copying ... ($percent %)" -status $_  -PercentComplete $percent -verbose
    copy $_.fullName -Destination c:\test 
    $i++
}

파일 이름을 직접 출력하려면 다음 방법을 사용합니다.

경로 포함

Copy-Item -Path $from -Destination $to –PassThru | ForEach-Object { Write-Host $_.FullName }

파일 이름만

Copy-Item -Path $from -Destination $to –PassThru | ForEach-Object { Write-Host $_.Name }

다음과 같은 방법으로 시도해 볼 것을 제안합니다.

(Copy-Item -Verbose C:\SrcDir\*.* c:\DstDir 4>&1).Message

여기서 메시지는 자세한 스트림/파이프라인이 아닌 출력 스트림/파이프라인으로 이동하므로 TFS 작업 스크립트와 같이 보다 일반적으로 작동합니다.

언급URL : https://stackoverflow.com/questions/13815656/get-the-list-of-files-that-are-getting-copied-in-powershell

반응형