pythonpathdirname

Current file targeting function returning an expected default value


I'm trying to use location_directory= os.path.dirname(os.getcwd()) for a folder location, but this function is returning a directory above, I will explain with results and what I ask for help on how to proceed. The framework what I´m using is dash . I´m trying to do this :

location_diretory= os.path.dirname(os.getcwd())

PATH = f"{location_diretory}/data/" 

When I try this PATH, return D:\name\data but the correct directory is D:\name\name\data.

I have 2 diretories in this project, i´m using pycharm for it. The current arquive .py, have the same name in the Diretory "name" and Diretory "name2".


Solution

  • when you use location_directory= os.path.dirname(os.getcwd()) actually you search for not the current directory, but you search for parent directory (the directory thet containe the current directory)

    use this:

    location_directory= os.getcwd()
    PATH = f"{location_diretory}/data/"