1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-26 21:18:36 -06:00
random/folderify.py

31 lines
975 B
Python
Raw Normal View History

2022-11-25 22:57:27 -06:00
#!/usr/bin/env python3
# This is a simple script to find all video files in a folder and move them into their own folders.
# It also detects .srt subtitle files with matching names and moves them into their corresponding
# video file's folder.
import os
from pathlib import Path
path = os.getcwd()
files = (file for file in os.listdir(path)
if os.path.isfile(file) and Path(file).suffix in ['.mkv', '.mp4', '.avi', '.3gp'])
ctr = 0
for x in files:
filename = Path(x)
basename = str(filename.with_suffix(''))
if not os.path.isdir(basename):
os.mkdir(basename)
else:
print('The folder '+basename +
' already exists, please deal with that file manually.')
continue
os.rename(path+"/"+x, path+"/"+basename+"/"+x)
if os.path.isfile(basename+'.srt'):
os.rename(path+'/'+basename+'.srt', path +
'/'+basename+'/'+basename+'.srt')
ctr += 1
print(str(ctr)+' folder(s) created.')