<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def path():
 """ Detect config file path """

        # Detect config directory
        try:
            directory = os.environ["DID_DIR"]
        except KeyError:
            directory = CONFIG
        # Detect config file (even before options are parsed)
        filename = "config"
        matched = re.search("--confi?g?[ =](\S+)", " ".join(sys.argv))
        if matched:
            filename = matched.groups()[0]
        return directory.rstrip("/") + "/" + filename