Skip to content

Instantly share code, notes, and snippets.

@AmirAref
Created September 15, 2022 15:08
Show Gist options
  • Save AmirAref/804e95a9505cf82c435632df4d43edbb to your computer and use it in GitHub Desktop.
Save AmirAref/804e95a9505cf82c435632df4d43edbb to your computer and use it in GitHub Desktop.
this a simple python script to create folders for movies files and move them to the new fodlers
import os
from glob import glob
from pathlib import Path
import re
import shutil
def main():
# grab movies files
movie_files = [item for item in glob('*.mp4')]
movie_files += [item for item in glob('*.mkv')]
for filename in movie_files:
# detect movie name
match = re.match(r'([\w. ]+?\d{4})\.', filename, re.I)
if not match:
continue
# return print('Sorry can\'t find the pattern !')
# create folder
folder_name = match.group(1).replace('.', ' ')
folder_name = Path(folder_name)
os.mkdir(folder_name)
# move the movie to it's folder
shutil.move(filename, folder_name / filename)
print(folder_name)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment