Python Scripts: Difference between revisions
Content added Content deleted
Line 687: | Line 687: | ||
<pre> |
<pre> |
||
#!/usr/bin/env python3 |
#!/usr/bin/env python3 |
||
⚫ | |||
import os |
import os |
||
import imghdr |
import imghdr |
||
Line 693: | Line 694: | ||
directory = sys.argv[1] |
directory = sys.argv[1] |
||
# Need to add a section for no extensions |
|||
⚫ | |||
for root, dirs, files in os.walk(directory): |
for root, dirs, files in os.walk(directory): |
||
Line 706: | Line 704: | ||
# find files with the (incorrect) extension to rename |
# find files with the (incorrect) extension to rename |
||
if |
if ext: |
||
if ftype != |
if ftype != ext: |
||
if ftype != None: |
|||
# rename the file |
# rename the file |
||
shutil.move(file, file.replace(ext,ftype)) |
shutil.move(file, file.replace(ext,ftype)) |
||
print (file, ext, ("=>"), ftype) |
print (file, ext, ("=>"), ftype) |
||
# in case it can't be determined, mention it in the output |
# in case it can't be determined, mention it in the output |
||
else: |
|||
print("could not determine: "+file) |
|||
else: |
else: |
||
print( |
print (name, "correct extension") |
||
else: |
else: |
||
print(file, "No Extension detected") |
|||
print ("done") |
print ("done") |