Skip to content

Instantly share code, notes, and snippets.

@97997
Created April 11, 2023 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 97997/9d1b1a4cbd396a3835e900fc8c24c88e to your computer and use it in GitHub Desktop.
Save 97997/9d1b1a4cbd396a3835e900fc8c24c88e to your computer and use it in GitHub Desktop.
This script will open a random folder within a list of folders and will load said folder into the music player
# This script will open a random folder within a list of folders and will load said folder into the music player
# You need to set up the variables "music_player_executable" and "music_folders"
import os
import random
import subprocess
def open_random_folder(folder_path):
# Get a list of all the folders in the given path
folder_list = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]
# Choose a random folder from the list
random_folder = os.path.join(folder_path, random.choice(folder_list))
# Open the random folder in Windows Explorer
subprocess.Popen(f'explorer "{random_folder}"')
return random_folder
# Example usage
music_folders = [r"Y:\music", r"Y:\albums"]
music_player_executable = r"C:\AIMP.exe"
while True:
folder_path = random.choice(music_folders)
picked_random_folder = open_random_folder(folder_path)
str_comma = "\""
command = str_comma + music_player_executable + str_comma + " " + str_comma + picked_random_folder + str_comma
print(command)
result = subprocess.run(command, capture_output=True, text=True)
print(result.stdout)
input("Press enter to run the program again")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment