Skip to content

Instantly share code, notes, and snippets.

@greencoder
Last active January 18, 2023 22:38

Revisions

  1. greencoder revised this gist Jan 18, 2023. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion copy.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    import glob
    import pathlib
    import random
    import shutil
  2. greencoder created this gist Jan 18, 2023.
    19 changes: 19 additions & 0 deletions copy.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import glob
    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