Skip to content

Instantly share code, notes, and snippets.

@aahnik
Created May 1, 2021 15:56
Show Gist options
  • Save aahnik/802d07dabb0b4b1c08ad142148fcd8cc to your computer and use it in GitHub Desktop.
Save aahnik/802d07dabb0b4b1c08ad142148fcd8cc to your computer and use it in GitHub Desktop.
Create part subfolders from a folder containing large no of files
# AAHNIK 2021
# ditch windows, may fail there
# for my personal use, i dont care to write a more detailed docs
import os
path = os.getcwd()
path = "/home/aahnik/Downloads/Telegram Desktop/dharmic_cause_ChatExport_2021-04-30/files"
# change this
limit = 1024
# _range =
os.chdir(path)
files = os.listdir()
print(f"No of files found in directory = {len(files)}")
input(
"Are you sure you want to partize ? This action cannot be undone !\nPress [CTRL + C] to quit or [ENTER] to continue ...\n"
)
total = 99999999999
part_no = 0
# change this
# your next part no - 1
# or your current last part no
def dd(integer: int):
if integer < 0:
raise ValueError
if integer < 10:
return f"0{integer}"
return f"{integer}"
for file in files:
input()
if os.path.isdir(file):
continue
file_size = os.path.getsize(file) / ((1024 * 1024))
file_size = round(file_size, 3)
if total >= limit:
print(f"total = {total}")
total = 0
print(f"total = {total}")
part_no += 1
print(f"part no = {part_no}")
os.makedirs(f"part{dd(part_no)}", exist_ok=True)
total += file_size
print(f"total = {total}")
print(f"{file} {file_size} MB")
new_path = f"part{dd(part_no)}/{file}"
os.rename(file, new_path)
print(f"moved to {new_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment