Reputation: 3
$destinationFolder = "C:\Users\Jimmy\Desktop\Saves"
$rootFolder = "C:\Users\Jimmy\Desktop\test"
$subFolder = "\sales"
$fileName = "hello.txt"
$Dir = get-childitem $rootFolder |
select -first 10 |
?{ $_.PSIsContainer } |
Sort-Object { [regex]::Replace($_.Name, '\d+', { $args[0].Value.PadLeft(20) }) }
[array]::Reverse($Dir)
$Dir | format-table FullName
Foreach ($i in $Dir){
if(Test-Path $($i.FullName + $subFolder + "\" + $fileName)){
#echo $($i.FullName + $subFolder)
get-childitem $($i.FullName + $subFolder) |
where {$_.Name.ToLower() -eq $fileName.ToLower()} |
Copy-Item -Destination $destinationFolder
echo $("just copied " + $fileName + " from " + $i.FullName.Trim())
break;
}else{
echo $("Could not find " + $fileName + " in " + $i.FullName.Trim())
}
}
I usually use this script to copy large files from one location to another. I want to add a progress bar so I have some indication of the file being copied etc.
I would like to add a write-progress [ooooo ]
type of thing, but I'm unsure how to do it.
Upvotes: 0
Views: 3087
Reputation: 26170
replace your foreach statement with this :
$i=1
$dir| %{
[int]$percent = $i / $dir.count * 100
Write-Progress -Activity "Copying ... ($percent %)" -status $_ -PercentComplete $percent -verbose
copy $_.fullName -Destination $destinationFolder
$i++
}
Upvotes: 2