Skip to content

Instantly share code, notes, and snippets.

@QuietMisdreavus
Created May 13, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuietMisdreavus/de2c5277e45533e5c9181eda1c70606a to your computer and use it in GitHub Desktop.
Save QuietMisdreavus/de2c5277e45533e5c9181eda1c70606a to your computer and use it in GitHub Desktop.
old script to import files into a wallpaper directory
#!/usr/bin/env python3
import os
from os.path import splitext
import hashlib
pictypes = ".png", ".jpg", ".bmp", ".gif"
ls = os.listdir(".")
def lsmd5():
ret = []
for name in ls:
_, ext = splitext(name)
if ext in pictypes:
with open(name, "rb") as file:
m = hashlib.md5()
m.update(file.read())
ret.append((name, m.hexdigest() + ext))
return ret
def massrename(list):
for names in list:
if names[1] not in ls:
try:
os.rename(names[0], names[1])
except OSError:
print(names[0] + ", " + names[1] + " rename failed")
if __name__ == "__main__":
massrename(lsmd5())
ls = os.listdir(".")
for file in ls:
_, ext = splitext(file)
if ext in pictypes:
try:
os.rename(file, "../"+file)
except OSError:
print(file + " move failed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment