Last active
January 18, 2023 22:38
-
-
Save greencoder/057b0f51355faf67d353239a53e95794 to your computer and use it in GitHub Desktop.
Randomly copy MP3 files to a new directory until the target directory reaches a certain file size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
import random | |
import shutil | |
mp3_files = list(pathlib.Path('/Users/scott/Desktop/Music').rglob('*.mp3')) | |
dst_dir = pathlib.Path('/Users/snewman/Desktop/CopiedMusic') | |
TARGET_SIZE = 1979999999 | |
for x in range(0, len(mp3_files)): | |
src_file = random.choice(mp3_files) | |
dst_file = dst_dir / src_file.name | |
shutil.copyfile(src_file, dst_file) | |
directory_size = sum(f.stat().st_size for f in dst_dir.glob('*.mp3') if f.is_file()) | |
if directory_size < TARGET_SIZE: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment