0

I need to get the full path of a file by providing its filename in python 2.7. Unfortunately I am not allowed to use the pathlib module.

 Example: 
filename: python.exe
full path that i want to print :  C:\app\tools\python27\python.exe

Thanks in advance for everyone who takes some time to response.

Dj_ 96
  • 185
  • 1
  • 4
  • 11

1 Answers1

0

Look at the thread at: How do I get the full path of the current file's directory?

I'm unsure on how you are implementing this in your code, but the "pathlib" (for over v3) and "os" (for under v3) library should be able to help.

Apologies if you had already looked at that thread and didn't find an answer!

  • thank you, but i have already looked at it. Unfortunately, as mentioned in the question i am not allowed to use the pathlib module, and the code for python 2.7: os.path.dirname(os.path.abspath(__file__)) just gives me the cwd – Dj_ 96 Feb 24 '20 at 16:01
  • And no luck using "os.path"? – HappyDragon Feb 24 '20 at 16:03
  • Nope, just giving me the cwd – Dj_ 96 Feb 24 '20 at 16:04
  • Not sure then, the only way I can think of is using the os. https://docs.python.org/2/library/os.path.html. Good luck finding a solution :( – HappyDragon Feb 24 '20 at 16:11