Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import os
import shutil
from PIL import Image
### Convert from [FORMAT_1] to [FORMAT_2] ###
### Uncomment when needed ###
##yourpath = os.getcwd()
##for root, dirs, files in os.walk(yourpath, topdown=False):
## for name in files:
## print(os.path.join(root, name))
## if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
## if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".png"):
## print("A tiff file already exists for %s" % name)
## # If a png is *NOT* present, create one from the tiff.
## else:
## outfile = os.path.splitext(os.path.join(root, name))[0] + ".png"
## try:
## im = Image.open(os.path.join(root, name))
## print("Generating png for %s" % name)
## im.thumbnail(im.size)
## im.save(outfile, "PNG", quality=100)
## except(Exception, e):
## print(e)
## os.remove(os.path.join(root,name))
##
## Code adapted from Anbarasan Thangapalam
## https://stackoverflow.com/questions/28870504/converting-tiff-to-jpeg-in-python
######################################################
### Split images to pre and post folders
yourpath = os.getcwd()
for root, dirs, files in os.walk(yourpath, topdown=False):
for name in files:
if 'post' in os.path.splitext(os.path.join(root, name))[0].lower():
shutil.move(os.path.join(root, name),root+'\post\\')
elif 'pre' in os.path.splitext(os.path.join(root, name))[0].lower():
shutil.move(os.path.join(root, name),root+'\pre\\')