""" By Brian Tomasik First written: 2018 May 23; last update: 2018 May 23 This program checks whether any files or folders are too long within the directory from which you run the program, and recursively in subdirectories. By default, "too long" refers to the limits on file and folder length that I think are imposed in Google Takeout exports: 50 characters for folders, and 54 characters for filenames with an extension. (I haven't checked in detail that this program finds exactly the same set of folder/file names that Google Takeout would truncate, but I'm guessing what I have is close enough most of the time.) Running this program directly will use the default character limits: python find_too_long_file_and_folder_names.py You can optionally set the character limit with an input parameter, like this: python find_too_long_file_and_folder_names.py 45 Doing that would find folders longer than 45 characters and files, if they have extensions, that are longer than 49 characters. """ import sys import os DEFAULT_MAX_CHARS = 50 EXTRA_CHARS_ALLOWED_FOR_EXTENSION = 4 def run(): max_chars_if_no_extension = DEFAULT_MAX_CHARS if len(sys.argv) > 1: max_chars_if_no_extension = int(sys.argv[1]) assert max_chars_if_no_extension >= 1, "Names need to have at least 1 character." max_chars_with_extension = max_chars_if_no_extension + EXTRA_CHARS_ALLOWED_FOR_EXTENSION for (path, dirs, files) in os.walk('.'): for dir_name in dirs: if len(dir_name) > max_chars_if_no_extension: print os.path.join(path, dir_name) for filename in files: main_filename, extension = os.path.splitext(filename) max_chars_limit_for_this_file = max_chars_with_extension if len(extension) > 0 else max_chars_if_no_extension if len(filename) > max_chars_limit_for_this_file: print os.path.join(path, filename) if __name__ == "__main__": run()