726
Finished Programs / Re: DONE: In sub-folders, delete all files except the largest
« Last post by 4wd on August 14, 2018, 06:43 AM »Quick and dirty:
Change <SRCE> to the source directory, (eg. Z:\test -- the parent of all the sub-directories), change <DEST> to the destination directory, (eg. K:\output), and it should copy the largest file in every sub-directory of the source to the destination, (directory tree is NOT preserved).
If there's an existing file of the same name it'll just skip copying that file, (ie. nothing gets overwritten).
eg.
Code: PowerShell [Select]
- Get-ChildItem <SRCE> -Recurse -Directory | % { Get-ChildItem $_.FullName -File | Sort-Object Length -Descending | Select-Object -First 1 | Copy-Item -Destination <DEST> }
Change <SRCE> to the source directory, (eg. Z:\test -- the parent of all the sub-directories), change <DEST> to the destination directory, (eg. K:\output), and it should copy the largest file in every sub-directory of the source to the destination, (directory tree is NOT preserved).
If there's an existing file of the same name it'll just skip copying that file, (ie. nothing gets overwritten).
eg.
Code: PowerShell [Select]
- Get-ChildItem Z:\test -Recurse -Directory | % { Get-ChildItem $_.FullName -File | Sort-Object Length -Descending | Select-Object -First 1 | Copy-Item -Destination K:\output }

Recent Posts

