Progressbar directory recursive
Posted: Thu Dec 06, 2018 3:13 am
I'm using this code to show a progressbar for copying files.
Now I would like to do the same thing with the recursive copy of directories
The directories have thousands of files but I see the progressbar only increase when the copy of the entire dir is completed while I would like the progression to be shown when copying all the files. How could I modify the script to get all this? Thank you
Code: Select all
$selectedPath = "c:\test"
$files = Get-ChildItem $selectedPath -Filter *.txt
if ($files -eq $null -or $files.Count -eq 0)
{
#No files to backup
return
}
#Initialize the Progress Bar
$progressbar1.Maximum = $files.Count
$progressbar1.Step = 1
$progressbar1.Value = 0
#Create the Backup Folder
$destination = ('{0}\\Backup' -f $selectedPath)
[System.IO.Directory]::CreateDirectory($destination)
#Copy the files and update the progress bar
foreach ($file in $files)
{
Copy-Item ('{0}\\{1}' -f $selectedPath, $file) -Destination $destination
$progressbar1.PerformStep()
}
Code: Select all
$files = Get-ChildItem -Path $selectedPath | Where-Object { $_.Name -match "@" }
foreach ($file in $files)
{
Copy-Item ('{0}\\{1}' -f $selectedPath, $file) -Destination $destination -Recurse -Force
$progressbar1.PerformStep()
}