Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HmnCpt

macrumors newbie
Original poster
Apr 26, 2021
4
0
Hi,

I've done a fair bit of digging but have only found 'solutions' that haven't worked for me.

I'm after an app or terminal script that can randomly select X amount of files from within many subfolders within a main folder, and copy them to my desktop. Has anybody had a experience with successfully doing this?

Any help would be greatly appreciated.

2017 iMac running Ventura 13.6.1
 

Slartibart

macrumors 68040
Aug 19, 2020
3,140
2,815
there are various solutions for this using the terminal… you might have to up your google-fu 😀This is one:

#!/bin/bash # Reads a given folder and picks a random file. # The directory you want to use. You could use "$1" instead if you # wanted to parametrize it. DIR="/path/to/" # DIR="$1" # Internal Field Separator set to newline, so file names with # spaces do not break our script. IFS=' ' if [[ -d "${DIR}" ]] then # Runs ls on the given folder, and dumps the output into a matrix, # it uses the new lines character as a field delimiter, as explained above. # file_matrix=($(ls -LR "${DIR}")) file_matrix=($(ls -R $DIR | awk '; /:$/&&f{s=$0;f=0}; /:$/&&!f{sub(/:$/,"");s=$0;f=1;next}; NF&&f{ print s"/"$0 }')) num_files=${#file_matrix[*]} # This is the command you want to run on a random file. # Change "ls -l" by anything you want, it's just an example. ls -l "${file_matrix[$((RANDOM%num_files))]}" fi exit 0

here are more.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.