w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python: Check if data file exists relative to source code file

If the parent directory of the two directories are always the same this should work:

import os
path_to_script = os.path.realpath(__file__)
parent_directory = os.path.dirname(path_to_script)

for root, dirs, files in os.walk(parent_directory):
    for file in files:
        if file == 'text.xml':
            path_to_xml = os.path.join(root, file)

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.