0

I'm trying to make a python package and I want to take input from the user and save the info in a .example folder in the root directory so that I can access that info later. This is what I implemented but it's not working -

def root_path():
    return os.path.abspath(os.sep)

if os.path.isdir(os.path.join(root, ".example")):
    #get info
else:
    #create .example in root

I want this to work on all operating system (Linux, MacOs and Windows majorly).

Does the isdir() function not work with hidden directories? What is the right way to do this?

2 Answers2

1

To check if a path exists or not, you can do this

>>> import os
>>> os.path.exists(".hidden-folder")
True
bhuvan
  • 11
  • 1
0

You can simply check if .example is a directory or not by using:

>>> import os.path
>>> os.path.isdir('.example') 

It will give you True in case .example exists and is a directory. Otherwise, it will return False.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228