Recursively rename file extensions
Question: I am having a difficult time creating a python script that will rename file
extensions in a folder and continue to do so in sub directories. Here is the
script I have thus far; it can only rename files in the top directory:

    
    
    #!/usr/bin/python
    # Usage: python rename_file_extensions.py
    
    import os
    import sys
    
    for filename in os.listdir ("C:\\Users\\username\\Desktop\\test\\"): # parse through file list in the folder "test"
    
        if filename.find(".jpg") > 0: # if an .jpg is found
    
                newfilename = filename.replace(".jpg","jpeg") # convert .jpg to jpeg
    
                os.rename(filename, newfilename) # rename the file
    


Answer: You can process the directory like this:

    
    
    import os
    
    def process_directory(root):
    
        for item in os.listdir(root):
            if os.path.isdir(item):
                print("is directory", item)
                process_directory(item)
            else:
                print(item)
                #Do stuff
    
    process_directory(os.getcwd())
    

Although, this isn't really necessary. Simply use `os.walk` which will iterate
through all toplevel and further directories / files

