vendredi 30 août 2019

How to shuffle files within a directory

I am trying to shuffle all the mp3 files within a directory on a micro sd card and moving it to another directory, as it plays in order. I am using Python 3 for this. I just can't get them to randomly switch the order they are presented in. Within the directory under arranged by, "none" is checked.

I have tried to use random.shuffle to shuffle the files in the location, however I get this error:

Traceback (most recent call last): File "/Users/lewislartey/Desktop/Shuffle.py", line 8, in random.shuffle(file) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/random.py", line 278, in shuffle x[i], x[j] = x[j], x[i] TypeError: 'str' object does not support item assignment

Here is my code:

import os
import random
import shutil
import glob
music = '/Volumes/SD/lit'
destination = '/Users/myusername/Desktop/TEST'
for file in glob.glob("/Volumes/SD/lit*/*.mp3"):
    random.shuffle(file)

.




Aucun commentaire:

Enregistrer un commentaire