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

    Join Date
    Jan 2013
    Rep Power

    File organisation

    hi im trying to create a script that would allow for me to be able to have files automatically sorted in a folder.
    there are a few things which i need to be carried out but there is one bit that i cant figure out, what i need to do is be able to get the first character of every file, i then need to create a folder for every unique value the closest i have come to so far is this:
    import os
    from os import listdir
    import dircache
    import sys
    import shutil
    import dircache
    import glob

    path = "C:\\Users\\hra\\Desktop\\fg"
    for fname in dirList:
    print fname

    myList = fname
    [x[0] for x in myList]
    print "my list = ", myList

    fCounter = len(glob.glob1("C:\\Users\\hra\\Desktop\\fg","f*"))
    mCounter = len(glob.glob1("C:\\Users\\hra\\Desktop\\fg","m*"))
    bCounter = len(glob.glob1("C:\\Users\\hra\\Desktop\\fg","b*"))
    #print "all files = ", countall
    print "f = ", fCounter
    print "m = ", mCounter
    print "b = ", bCounter
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    Your description sounds a lot like
    import os
    path = "C:\\Users\\hra\\Desktop\\fg"
    # why sort???
    first_characters_of_items_in_dirList = [name[0] for name in dirList]
    uniques = set(first_characters_of_items_in_dirList)
    for d in uniques:
        if (not os.path.isfile(d)) and (not os.path.isfile(d)):
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo