Skip to content

Instantly share code, notes, and snippets.

@javiergarciad
Created October 23, 2018 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javiergarciad/842ef7393959b1af89484621288ea2b9 to your computer and use it in GitHub Desktop.
Save javiergarciad/842ef7393959b1af89484621288ea2b9 to your computer and use it in GitHub Desktop.
import pathlib
import logging
import re
FORMAT = '%(asctime)s %(levelname)-7s %(message)-70s %(name)s.%(funcName)s'
def setup_logging():
"""
Setup logging configuration
"""
# set up logging to file
cwd = pathlib.Path.cwd()
log_file = cwd / 'log.log'
logging.basicConfig(filename=log_file,
format=FORMAT,
level=logging.INFO)
# set up logging to console
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter(FORMAT)
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
def list_of_files(dir_path):
dir_path = pathlib.Path(dir_path)
dir_path = pathlib.Path.expanduser(dir_path)
logger.info('Working on directory: {}'.format(dir_path))
# Define the set of files to work with
files = dir_path.glob('**/*.mkv')
for f in files:
filename = f.stem
parent = f.parts[-2]
#Do something
print(parent , filename)
if __name__ == '__main__':
dir_str = '/media/javier/My Passport/Media/TV Shows/Naruto Shippuden (Complete Series 001-500)'
setup_logging()
logger = logging.getLogger(__name__)
list_of_files(dir_path=dir_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment