-1

I have directory '/batchjobs/files/'. I want to know the complete path of it.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Ravi Ranjan
  • 115
  • 1
  • 1
  • 12
  • 3
    I think this is what you are after: [How to get an absolute file path in Python](https://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python). Short answer: `os.path.abspath('/batchjobs/files/')` – JNevill Jul 28 '22 at 15:05
  • @JNevill I am looking for directory complete path, not a file's. – Ravi Ranjan Jul 28 '22 at 15:18
  • If you check on that duplicate link you will find lots of options, which is why I linked it. Perhaps the very top answer that is showing: `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. – JNevill Jul 28 '22 at 15:20
  • `/batchjobs/files` _is already_ an absolute path -- `/` is the root directory. It would be a relative path if it was `./batchjobs/files` or `batchjobs/files` – Pranav Hosangadi Jul 28 '22 at 15:48

1 Answers1

0

You can use the pathlib library.

import pathlib
print(pathlib.Path('/batchjobs/files/').absolute())
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
  • 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/ – Ravi Ranjan Jul 28 '22 at 15:17
  • actually i think the parent. part was unnecessary, just made an edit to my answer, try this one instead pls – Dennis Kozevnikoff Jul 28 '22 at 15:19