-2

I’m doing a coding project and wanted to ask something that would make my life so much easier.

Is there a syntax I can use to tell python to find the full file path if I know the latter half of it? For example if the full address is C:\a\b\c\d\e\f\g.file, but I know that I’m looking for \d\e\f\g.file, is there something I can do to find at least 1 path on my computer that would have that latter part of a file path. Sorry if this is badly worded, first time asking a question on here.

Thanks in advance!

ingvar
  • 4,169
  • 4
  • 16
  • 29
Mathew Major
  • 39
  • 1
  • 3
  • 1
    Does this answer your question? [How to get an absolute file path in Python](https://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python) – LeKhan9 Apr 15 '20 at 22:55
  • Actually, this smells like a duplicate question to me. I noticed after answering, besides my answer might not apply across OS. – LeKhan9 Apr 15 '20 at 22:56

1 Answers1

0

It's always good to provide an example of what you've tried. However, this seems straightforward to me.

You might be looking for absolute path?

import os

relative_path = '\d\e\f\g.file'
os.path.abspath(relative_path)
LeKhan9
  • 1,300
  • 1
  • 5
  • 15