Here's how I'm currently guessing whether a path leads to a theoretical file or folder:
def __init__(self, path:str, is_dir:bool=None):
# checks
if is_dir is None: is_dir = path.endswith('/') or path.endswith('\\') or os.path.isdir(path) or '.' not in path # guess if path is pointing to a file
self.is_dir = is_dir
# note: Because both files and folders can, but don't have to include dots in their names,
# this check is just a basic guess.
#
# files without extensions that were not yet created will be recognised as folders
# and
# folders with dots in their name that were not yet created will be recognised as files
#
# If you know of a better solution to this problem (which I frankly don't think exists),
# please implement it here.
Is there a better way that works on both UNIX-likes and Windows? (and possibly even elsewhere?)
(in case that the question is confusing: by theoretical I mean that it might not exist (yet))