Skip to content

Instantly share code, notes, and snippets.

@97997
Last active December 26, 2020 23:19
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/3a0aa4296dda070b6cdb1805d0acae59 to your computer and use it in GitHub Desktop.
Save 97997/3a0aa4296dda070b6cdb1805d0acae59 to your computer and use it in GitHub Desktop.
fill disk with random music
import folderooptest
import random
import shutil
import os
targetFolder = r"J:\BlackBerry\music" + "\\"
fill_until_there_are_x_free_megas = 100
music_collection_folder = r"G:\Albums"
path_to_check = r"J:\BlackBerry\music"
folder_to_check_instance = folderooptest.Folder(path_to_check)
def getFreeMegas(path='J:\\'):
disk_usage = shutil.disk_usage(path)
bytez = disk_usage.free
kbytez = bytez/1024
mbytez = kbytez/1024
gbytez = mbytez/1024
return mbytez
def getFreeGBytes(path='J:\\'):
disk_usage = shutil.disk_usage(path)
bytez = disk_usage.free
kbytez = bytez/1024
mbytez = kbytez/1024
gbytez = mbytez/1024
return gbytez
musicFolder = folderooptest.Folder(music_collection_folder)
randomMusic = musicFolder.get_files_with_extension_fullpath('.mp3')
random.shuffle(randomMusic)
current_free_megas = getFreeMegas()
initial_free_space = current_free_megas
# fill until there are 6000 megas of free space
while current_free_megas > fill_until_there_are_x_free_megas and len(randomMusic) > 0:
print("Current " + str(int(current_free_megas)) + " MB / Quota: "
+ str(fill_until_there_are_x_free_megas) + " MB")
filename = randomMusic.pop()
target = targetFolder+os.path.basename(filename)
if not os.path.isfile(target) and \
not os.path.basename(filename) in folder_to_check_instance.all_files_on_subfolders_onlybasename:
print("Copying [" + os.path.basename(filename) + "] to [" + os.path.dirname(target) + "]")
shutil.copy(filename, target)
else:
print("File [" + filename + "] was skipped because it's already on disk")
current_free_megas = getFreeMegas()
print("Device has " + str(int(current_free_megas)) + " free megabytes, filling until device has " +
str(fill_until_there_are_x_free_megas) + " free megabytes...")
percentage = 100+((100/(fill_until_there_are_x_free_megas - initial_free_space))
* (current_free_megas - fill_until_there_are_x_free_megas))
print(str(int(percentage)) + "% completed\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment