Removing randomly generated file extensions from .jpg files using python
Question: I recently recovered a folder that i had accidentally deleted. It has .jpg and
.tar.gz files. However, all of the files now have some sort of hash extension
appended to them and it is different for every file. There are more than 600
files in the folders. So example names would be:

    
    
    IMG001.jpg.3454637876876978068
    IMG002.jpg.2345447786787689769
    IMG003.jpg.3454356457657757876
    

and

    
    
    folder1.tar.gz.45645756765876
    folder2.tar.gz.53464575678588
    folder3.tar.gz.42345435647567
    

I would like to have a script that could go in turn (maybe i can specify
extension or it can have two iterations, one through the .jpg files and the
other through the .tar.gz) and clean up the last part of the file name
starting from the . right before the number. So the final file names would end
in .jpg and .tar.gz

What I have so far in python:

    
    
    import os
    
    def scandirs(path):
        for root, dirs, files in os.walk(path):
            for currentFile in files:
                os.path.splitext(currentFile)
    
    scandirs('C:\Users\ad\pics')
    

Obviously it doesn't work. I would appreciate any help. I would also consider
using a bash script, but I do not know how to do that.


Answer: `shutil.move(currentFile,os.path.splitext(currentFile)[0])`

at least I think ...

