Friday 13 June 2014

Get Parent Directory via Python

Get the parent directory of a folder/file in python. Using the "os" library its possible using python.


Lets try to understand with an example

>>> import os
>>> os.path.dirname('D:\Workspace\8.0.0.0 - INT')

Output will be as: 'D:\\Workspace'

Same if want to get the parent directory of file,

>>> os.path.dirname('D:\Workspace\8.0.0.0 - INT\AdapterFactory.py')
Out put will be as: 'D:\\Workspace\\8.0.0.0 - INT'

Thanks.

2 comments:

  1. This post was very informative. Its really amazing blog with very much helpful information. I will bookmark your amazing site and i want visit here again. Thanks for sharing this.

    catering prasmanan enak murah

    ReplyDelete