[GET] Python script, organize photos.

Discussion in 'Black Hat SEO Tools' started by oToom, Jan 12, 2013.

  1. oToom

    oToom Newbie

    Oct 4, 2009
    Likes Received:
    Right okay. Sorry if this is in the incorrect place. I didn't really know where to put it to share it.
    This is nothing special. It was something I needed.

    I had over 8000 images of all file extensions. .png .jpeg .gif etc. And needed to sort them out. So here goes.

    #! /usr/bin/env python
    import sys
    import os
    import shutil 
    folder = os.path.join('F:\\', 'ImageFolder') # Folder in which you have all your images in. 
    destination = os.path.join('F:\\', 'jpeg') # Folder in which you wish to move the images to. In this case jpeg because I want all the jpeg in a folder.
    extmove = 'jpg' # The extension you wish to organize. 
    num = 0 # Variable simply to use after to count images. 
    for filename in os.listdir(folder): #Run through folder.
            extension = filename.split(".")[-1] # This strips the extensions ready to check and places into the extension
            if extension == extmove: # If statement. If the extension of the file matches the one set previously then..
                shutil.move(folder + "\\" + filename, destination) # Move the file from the folder to the destination folder. Also previously set. 
            num = num + 1
            print num
            #print filename, extension

    Thanks james in the coding section for helping me out on why i couldn't get the output expected to begin with.

    Cheers hope someone else can use it to help.