0
$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.

1 Answer 1

2

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++
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.