On 13/10/10 15:26, Bishwarup Banerjee wrote:
I want to get the absolute path of the Directory I pass explicitly. Like
functionName("\abcd").
I should pass the name of the directory and the function should search for it in the Hard drives and return me the full path of location on the drive. I tried using os.path, but didn't succeed.

One way to achieve this is to fetch a recursive directory list for all drives, and then search for your directory_name.endswith("abcd") in each list. But what would you do with multiple occurrences ?

Here's a function to fetch a recursive directory list:

import os.path

def getRecursiveDirList(path):
    dir_list = []
    if (os.path.isdir(path)):
        try:
            files = os.listdir(path)
            files.sort()
        except:
            files = []
        for x in files:
            full_path = os.path.join(path, x)
            if (os.path.isdir(full_path)):
                dir_list.append(os.path.join(full_path,''))
                for full_path in getRecursiveDirList(full_path):
                    dir_list.append(full_path)
    return dir_list

I've only tested this function under Linux.
It's also probably sub-optimal.

I don't know how to enumerate all your windows device letters.

regards,
-kt
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to