0

I want to copy all JPGs within a directory (including subfolders) to a target destination (flat hierarchy). My Powershell Script seems super slow :(

Any ideas how to make the fastest approach? Is robocopy a faster solution? It seems that Robocopy always also creates the folder of the JPG. But I want it flat like C:\destination\image1.jpg C:\destination\image2.jpg C:\destination\image3.jpg

Is it possible that only images are copied that arent already in the target folder?

Get-ChildItem -Path "R:\XXX\*" -Include *.jpg -Recurse | Copy-Item -Destination $targetpath -verbose
Julian
  • 57
  • 3
  • 6
  • If you are going for speed I think a test for exist will slow you down. Is the script much longer then what you wrote here? What kind of location is r drive and the target? – dcaz Nov 11 '21 at 14:29
  • 1
    Replace `-Include` by `-Filter` which should be faster as it uses filter at the filesystem API level, instead of PoSh filter which is applied later. – zett42 Nov 11 '21 at 14:34
  • 2
    Check this out. It uses Windows batch commands (instead of PowerShell) along with ROBOCOPY. [ROBOCOPY - Copy folders content to a single folder](https://stackoverflow.com/a/8691073/2441) – aphoria Nov 11 '21 at 14:35

0 Answers0