Created
January 9, 2019 10:25
-
-
Save wodim/9464ad8c90072cecd8a40a625b5b97b3 to your computer and use it in GitHub Desktop.
Revisions
-
wodim created this gist
Jan 9, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import mimetypes import os import sys import magic try: dir = sys.argv[1] except IndexError: dir = os.getcwd() files = [f for f in os.listdir(dir) if os.path.isfile(os.path.join(dir, f))] for file in files: if file == sys.argv[0]: continue mimetype = magic.from_file(file, mime=True) extension = mimetypes.guess_extension(mimetype) if extension and not file.endswith(extension): os.rename(file, file + extension)