I have directory '/batchjobs/files/'. I want to know the complete path of it.
1 Answer
You can use the pathlib library.
import pathlib
print(pathlib.Path('/batchjobs/files/').absolute())
2 Comments
Ravi Ranjan
Thanks for the response @Dennis, but it returns /batchjobs only. I need to get the complete path of /batchjobs/files/. which will be something like /A/B/C/batchjobs/files/
Dennis Kozevnikoff
actually i think the parent. part was unnecessary, just made an edit to my answer, try this one instead pls
os.path.abspath('/batchjobs/files/')os.path.join( os.getcwd(), 'batchjobs/files/' )would do the trick? There's likely lots of ways to solve this and most of them are listed out as optional answers there./batchjobs/filesis already an absolute path --/is the root directory. It would be a relative path if it was./batchjobs/filesorbatchjobs/files