jeudi 3 mai 2018

Moving multiple files at random from dir to dir

I wrote a script that will copy a single file from one dir to another. Is there a way to select multiple? I.e. specifically 25% of the total number of files in the source dir? I have not been able to find a direct answer.

This is what I have.

files = os.listdir(source_dir)
index = random.randrange(0, len(files))
random_file = files[index]
shutil.copy(source_dir + random_file, output_dir)

Thanks.




Aucun commentaire:

Enregistrer un commentaire