#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Broken python script


    was wondering if anyone could see whats wrong with this script. All its supposed to do is move images into respectable folders or create them if not exist, but for some reason it tries to organize a folder directory too.

    Code:
    # sort multiple image sequences
    #
    # creates a folder if it doesn't exist for each image and moves the image to that folder
    
    import os
    from collections import OrderedDict
    
    #print('Starting Loop')
    for dirname, dirnames, filenames in os.walk('.'):
    	for filename in filenames:
    #		print('Filename: ' + filename)
    		p =  os.path.join(dirname, (os.path.splitext(os.path.splitext(filename)[0])[0]))
    #		print('P: ' + p)
    		if not os.path.exists(p):
    			os.mkdir(p)
    		if os.path.exists(os.path.join(p,filename)):
    			os.remove(os.path.join(p,filename))
    		os.rename(filename, os.path.join(p, filename))
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,904
    Rep Power
    481

    duplicate


    Given that leading white space is part of python syntax, and that the html formatting discards extra white space unless you tell it not to, please follow the instructions at my signature to fix your post. Thanks, Dave.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo