Skip to content

Instantly share code, notes, and snippets.

@patroqueeet
Created April 24, 2015 13:15
Show Gist options
  • Save patroqueeet/381aa5ceca59de02669e to your computer and use it in GitHub Desktop.
Save patroqueeet/381aa5ceca59de02669e to your computer and use it in GitHub Desktop.
In [11]: while True:
for t in Thumbnail.objects.all():
fname = os.path.basename(t.name)
dname = os.path.dirname(t.name)
h.join(root, dname)):.isfile(os.path.join(root, dname, fname)) and os.path.exists(os.path
for x in listdir(os.path.join(root,dname)):
if x[3:] == os.path.basename(t.name):
e, x[3:]) print "renaming", os.path.join(root,dname,x), os.path.join(root,dname
)) os.rename(os.path.join(root,dname,x), os.path.join(root,dname, x[3:])
time.sleep(3)
@patroqueeet
Copy link
Author

steal crumbled code from here...

if not os.path.isfile(os.path.join(root, dname, fname)) and os.path.exists(os.path.join(root,  dname)):
            for x in listdir(os.path.join(root,dname)):                                                   if x[3:] == os.path.basename(t.name):
                     print "renaming", os.path.join(root,dname,x), os.path.join(root,dname, x[3:])
                     os.rename(os.path.join(root,dname,x), os.path.join(root,dname, x[3:]))
    time.sleep(3)

@rafaqueque
Copy link

Final code:

from easy_thumbnails.models import Thumbnail
while True:
    for t in Thumbnail.objects.all():
        fname = os.path.basename(t.name)
        dname = os.path.dirname(t.name)
        if not os.path.isfile(os.path.join(root, dname, fname)) and os.path.exists(os.path.join(root,  dname)):
            for x in os.listdir(os.path.join(root,dname)):
                if x[3:] == os.path.basename(t.name):
                    print "renaming", os.path.join(root,dname,x), os.path.join(root,dname, x[3:])
                    os.rename(os.path.join(root,dname,x), os.path.join(root,dname, x[3:]))
    time.sleep(3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment