Created
September 15, 2022 15:08
-
-
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
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 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