#!/usr/bin/env python """ Recursively checks all filenames of a given directory. In case an unwanted character is found, the filename is printed to stdout. """ __date__="2011-07-17" __author__="Gernot WALZL" MAX_LENGTH=64 # In Joliet each path component can be up to 64 characters long. import sys import os import re def print_usage(): print("Usage:") print("check_filenames.py PATH") def is_valid_name(name): if len(name) > MAX_LENGTH: return False pattern = "\A[a-zA-Z0-9_ $\-\.]+\Z" if re.match(pattern, name) != None: return True return False def check_filenames(path="."): names = os.listdir(path) names.sort() for name in names: if not is_valid_name(name): print(path+os.sep+name) if os.path.isdir(path+os.sep+name): check_filenames(path+os.sep+name) if __name__=="__main__": if len(sys.argv) <= 1: print_usage() sys.exit(1) path = sys.argv[1] if path[-1] == os.sep: path = path[0:len(path)-1] if not os.path.isdir(path): print_usage() sys.exit(1) check_filenames(path)