vendredi 29 avril 2022

Randomly shuffling all files in a directory?

I am trying to find a solution with bash to shuffle a directory full of 2x3000 files of the type:

.mp4

.json (stores the metadata).

The .mp4 and .json are connected to each other so, the problem is:

I can shuffle both individually, but this loses the indirect connection in the process. So I would need a code, which stores the random value, into a variable and assign it to my .mp4+json package each.

The folder contains

  • 1.mp4
  • 2.mp4
  • 3.mp4
  • 3000.mp4

and also

  • 1.json
  • 2.json
  • 3.json
  • 3000.json

I´ve looked everywhere on the platform but didnt find a satisfying solution and its beyond my bash skills!

This was my base code:

for i in *; do mv "$i" $RANDOM-"$i"; done

paste <(printf "%s\n" *) <(printf "%s\n" * | shuf) |
  while IFS=$'\t' read -r from to; do mv -- "$from" "$to.mp4"; done

for f in *.mp4; do mv -- "$f" "${f%.mp4}"; done 

Thank you!

cheers Michael Schuller




Aucun commentaire:

Enregistrer un commentaire