Python Scripts: Difference between revisions
→Extensions Doctor
Line 693:
directory = sys.argv[1]
# Need to add a section for no extensions
Line 704 ⟶ 703:
# find the correct extension
ftype = imghdr.what(file)
ext = os.path.splitext(file)[1][1:]
# find files with the (incorrect) extension to rename
if ftype != ext:
if ftype != None:
# rename the file
shutil.move(file, file.replace(ext,ftype))
Line 716:
else:
print("could not determine: "+file)
print ("done")
</pre>
;List files with double extensions:
<pre>
#!/usr/bin/env python3
import os
import imghdr
import shutil
import sys
directory = sys.argv[1]
# Need to add a section for no extensions
for root, dirs, files in os.walk(directory):
Line 727 ⟶ 738:
file = root+"/"+name
#
fn1,
fn2, ext2 = os.path.splitext(fn1)
if ext == ext2:▼
if not
elif ext2 ==
print (
# shutil.move(file, fn1.replace(ext,ext2))
print (file, "has 2 Diff extensions")
# shutil.move(file, fn1.replace(ext,ext2))
else:
print (
print ("done")
</pre>
|