#!/usr/bin/python3

'''
Rename files in a subdirectory whose name is a date in the following format: mm-dd-yy
Example usage:
directory name:
	11-20-20
files in 11-20-20:
	file1.txt
	file2.txt
After running this script, the files should be named:
	11-20-20file1.txt
	11-20-20file2.txt	
'''
import os
import re

def contains_date(dir_name):
	regexp = re.compile(r'[0-9]{1,2}-[0-9]{1,2}-[0-9]{2}')
	return regexp.search(dir_name)
	

def main():
	curr_dir = os.getcwd()
	if not contains_date(curr_dir):
		print('{} does not have the format: mm-dd-yy, aborting'.format(curr_dir))
		return
	last_slash_idx = curr_dir.rfind('/') + 1
	date = curr_dir[last_slash_idx:]
	with os.scandir(curr_dir) as it:
		for entry in it:
			if entry.is_file() and not contains_date(entry.name):
				print(entry.name + ' ===> ' + date + entry.name)
				os.rename(entry.name, date + entry.name)
		
if __name__ == "__main__":
	main()
