Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import rename, listdir
- found = set()
- def read_dictionary():
- mydict = {}
- with open('dictionary.txt', 'r') as dict_file:
- for line in dict_file:
- line = line.strip()
- split_line = line.split('|')
- mydict[split_line[1]] = split_line[0]+'.mkv'
- return mydict
- def rename_files(files, rename_dict):
- for fname in fnames:
- if fname in rename_dict:
- print(fname, '->', rename_dict[fname])
- rename(fname, rename_dict[fname])
- def validate(fnames, mydict):
- files_set = set(fnames)
- missing = mydict.keys() - files_set
- lmissing = list(missing)
- lmissing.sort()
- for m in lmissing:
- print('missing expected file', m)
- if lmissing:
- raise Exception('missing expected files')
- mydict = read_dictionary()
- fnames = listdir('.')
- validate(fnames, mydict)
- rename_files(fnames, mydict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement