Answer the question
In order to leave comments, you need to log in
How to select multiple random files in a directory in PYthon?
AXIS - Windows.
Actually on a subject.
If 1 file needs to be selected, then it’s clear, something like this:
import os
from os import path
files = [f for f in os.listdir(dirToScreens) if path.isfile(f)]
Answer the question
In order to leave comments, you need to log in
import random
...
chosen_files = random.sample(files, 5) if len(files) > 4 else files
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question