Get the list of files that are getting copied in PowerShell

我的未来我决定 提交于 2019-12-12 09:28:42

问题


I am using the PowerShell Copy-Item command to copy a directory with files to another location.

I want to display all the files on the console that are getting copied so that I know the status of the copy command.


回答1:


If you just want to see that in console, use the -verbose switch:

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

If you want to get a list of files or directories:

$files = copy-item -path $from -destination $to -passthru | ?{$_ -is [system.io.fileinfo]}



回答2:


$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++
}



回答3:


I suggest to try it this way:

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

Here the messages go to the output stream/pipeline rather than the verbose stream/pipeline and so will work more generally such as in TFS task scripts.



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!