-1

e.g. a function should return:

  • stackpath = "config/openvpn/openvpn02.json"

for stackname = "openvpn02".

How would I search "openvpn02.json" in the config directory?

Dennis
  • 2,866
  • 7
  • 32
  • 49

1 Answers1

1

like this

import os

to_search = "filename"

for dirpath, dirnames, filenames in os.walk("."):
    for filename in [f for f in filenames if "".join(f.split(".")[:-1])==to_search]:
        print os.path.join(dirpath, filename)
Liam
  • 6,009
  • 4
  • 39
  • 53