Skip to content

Instantly share code, notes, and snippets.

@morriekken
Created July 1, 2020 06:15
Show Gist options
  • Save morriekken/118534adfefd84ef1ab5443e035fd2f1 to your computer and use it in GitHub Desktop.
Save morriekken/118534adfefd84ef1ab5443e035fd2f1 to your computer and use it in GitHub Desktop.
# Count files in current dir and all subdirectories
(Get-ChildItem *.jpg -Recurse -File | Measure-Object).Count
# Measure size of files in current directory and all subdirectories (in Gb)
(Get-ChildItem *.jpg -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1Gb
# Get 100 random jpg files and exclude FOLDER (you have to provide CountOfFiles)
Get-ChildItem -Exclude FOLDER | Get-ChildItem -Recurse -Filter *.jpg -File | Get-Random -Count CountOfFiles | Select-Object -First 100
# Same as above but copies selected files to DESTINATION_FOLDER
Get-ChildItem -Exclude FOLDER | Get-ChildItem -Recurse -Filter *.jpg -File | Get-Random -Count CountOfFiles | Select-Object -First 100 | Copy-Item -Destination DESTINATION_FOLDER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment