Skip to content

Instantly share code, notes, and snippets.

@subnomo
Last active August 14, 2016 15:28
Show Gist options
  • Save subnomo/7891bdca144f1a282703 to your computer and use it in GitHub Desktop.
Save subnomo/7891bdca144f1a282703 to your computer and use it in GitHub Desktop.
Made another version of previous script, this one moves gifs from all folders in current directory into "gifs" folders in their respective directories. (Does that sentence make sense?)
import os
count = 0
for folder in os.listdir('.'):
if not os.path.isdir(folder):
continue
for filename in os.listdir('./' + folder):
oldPath = './' + folder + '/' + filename
newPath = './' + folder + '/gifs/'
if filename == 'separateAllGifs.py':
continue
elif filename == 'log.txt': # Removes logs created by image ripping
os.remove(oldPath)
continue
elif os.path.isdir(filename):
continue
if filename[-3:] == 'gif': # If it's a gif, stash in gifs folder
count += 1
if not os.path.exists(newPath):
os.makedirs(newPath)
newPath = newPath + filename
if os.path.isfile(newPath):
os.remove(oldPath)
else:
print("Moving " + oldPath)
os.rename(oldPath, newPath)
if count == 0:
print("No gifs to move!")
else:
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment