Re: Help needed - To get path of a directory
> Dear Emmanuel, > > Thank you for your reply. > Actually what I want to do is, at the run time I want to know the location > of a specific directory. > Then I will add some file name to the path and load the file. > The directory can reside in any drive, depending on the user. Well... If you don't even know the path of the directory relative to the root of the drive... I hope your user is not in any hurry. Scanning a single drive is potentially very time-consuming, scanning them all will be awful (especially if your user has mounted, say, a huge network drive...). Don't you have any other, smarter way of finding out the directory? Like reading a configuration file or an entry in the registry? Cheers, Emm -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed - To get path of a directory
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"). On 13/10/2010 05:44, Kingsley Turner wrote: 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 ? [... snip useful code ...] I don't know how to enumerate all your windows device letters. http://timgolden.me.uk/python/win32_how_do_i/find-drive-types.html TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed - To get path of a directory
In message , Kingsley Turner wrote: > I don't know how to enumerate all your windows device letters. There are only 26 of them, so you can try them all, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed - To get path of a directory
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
Re: Help needed - To get path of a directory
Dear Emmanuel, Thank you for your reply. Actually what I want to do is, at the run time I want to know the location of a specific directory. Then I will add some file name to the path and load the file. The directory can reside in any drive, depending on the user. With Warm Regards, On Wed, Oct 13, 2010 at 12:03 PM, Emmanuel Surleau < emmanuel.surl...@gmail.com> wrote: > > Dear All, > > > > 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. > > > > I am using python 2.5 on windows platform. > > It will be very kind of you if you can guide me on this. > > What is your path relative to? The python file? The working directory? Can > it > be absolute? Or do you actually intend to "search for it in the hard > drives" > because you don't know where it is? > > Cheers, > > Emm > -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed - To get path of a directory
> Dear All, > > 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. > > I am using python 2.5 on windows platform. > It will be very kind of you if you can guide me on this. What is your path relative to? The python file? The working directory? Can it be absolute? Or do you actually intend to "search for it in the hard drives" because you don't know where it is? Cheers, Emm -- http://mail.python.org/mailman/listinfo/python-list
Help needed - To get path of a directory
Dear All, 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. I am using python 2.5 on windows platform. It will be very kind of you if you can guide me on this. With Warm Regards, -- http://mail.python.org/mailman/listinfo/python-list