venu madhav wrote:

Hello,
First of all thanks for your response. I've written a function as shown below to recurse a directory and return a file based on the value of n. I am calling this fucntion from my main code to catch that filename. The folder which it recurses through contains a folder having files with unicode names (as an example i've given earlier. -----------------------------------------------------------------------------
def findFile(dir_path):
    for name in os.listdir(dir_path):
        full_path = os.path.join(dir_path, name)
        print full_path
        if os.path.isdir(full_path):
            findFile(full_path)
        else:
            n = n - 1
            if(n ==0):
                return full_path
--------------------------------------------------------------------------------------------------

Because os.listdir() returns the list in arbitrary order (depends on platform and/or filesystem type), it is pretty useless to get the n'th file of a directory. With every call of your function, the n'th file may be a different one. Never rely on the order of items returned by os.listdir().

Ulli
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to