Python Scripts: Difference between revisions

Content added Content deleted
Line 687: Line 687:
<pre>
<pre>
#!/usr/bin/env python3
#!/usr/bin/env python3
# Need to write Results to a file in script dir
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
# Need to write Results to a file in script dir


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 ftype != ext:
if ext:
if ftype != None:
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("could not determine: "+file)
print (name, "correct extension")
else:
else:
print (name, "correct extension")
print(file, "No Extension detected")


print ("done")
print ("done")