获取在PowerShell中复制的文件列表

tus*_*ath 25 powershell copy-item

我正在使用PowerShell Copy-Item命令将包含文件的目录复制到另一个位置.

我想显示控制台上被复制的所有文件,以便我知道复制命令的状态.

Jac*_*kie 34

如果您只想在控制台中看到它,请使用-verbose开关:

copy-item -path $from -destination $to -verbose
Run Code Online (Sandbox Code Playgroud)

如果要获取文件或目录列表:

$files = copy-item -path $from -destination $to -passthru | ?{$_ -is [system.io.fileinfo]}
Run Code Online (Sandbox Code Playgroud)

  • `-Verbose` 报告了大量额外信息,有没有办法告诉它只输出复制的文件的名称? (3认同)

Loï*_*HEL 5

$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++
}
Run Code Online (Sandbox Code Playgroud)