# \[Shell\]\[Python\] cant find directories shown in path

**URL:** <https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [June 25, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623 "2025-06-25T17:26:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zeviraty](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/zeviraty/32/13507_2.png) [@Zeviraty](https://forum.codecrafters.io/u/Zeviraty)\
**Post date:** [June 25, 2025, 5:26pm UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623/1 "2025-06-25T17:26:04Z")

</div>

i am trying to complete #mg5 but it cant find the directories in path works locally:  
logs

```auto
Submitting changes (commit: b70de94)...

Our test runners might be experiencing downtime: https://status.codecrafters.io

Running tests. Logs should appear shortly...

[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
[tester::#MG5] [setup] export PATH=/tmp/bar:$PATH
[tester::#MG5] [setup] export PATH=/tmp/quz:$PATH
[tester::#MG5] [setup] PATH is now: /tmp/quz:/tmp/bar:/usr/local/bin:...
[tester::#MG5] [setup] Available executables:
[tester::#MG5] [setup] - my_exe
[tester::#MG5] Running ./your_program.sh
[your-program] $ type cat
[your-program] Traceback (most recent call last):
[tester::#MG5] ^ Line does not match expected value.
[tester::#MG5] Expected: "cat is /bin/cat"
[tester::#MG5] Received: "Traceback (most recent call last):"
[your-program] File "<frozen runpy>", line 198, in _run_module_as_main
[your-program] File "<frozen runpy>", line 88, in _run_code
[your-program] File "/app/app/main.py", line 64, in <module>
[your-program] main()
[your-program] ~~~~ ^^
[your-program] File "/app/app/main.py", line 47, in main
[your-program] for y in os.listdir(os.path.join(x)):
[your-program] ~~~~~~~~~~ ^^^^^^^^^^^^^^^^^
[your-program] FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/sbin'
[tester::#MG5] Assertion failed.
[tester::#MG5] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

View our article on debugging test failures: https://codecrafters.io/debug

```

code

```auto
import sys
import os

def typer(base,conduit:type) -> tuple:
    try:
        return (conduit(base),True)
    except:
        return (0,False)

def argparse(args,types:list[type]) -> tuple:
    tmp = []
    failed = [0,False]

    if len(types) > len(args):
        failed = [0,True]

    args = args[:len(types)]

    for idx,i in enumerate(args):
        typed = typer(i,types[idx])
        if typed[1] == False:
            failed[0] = idx
            failed[1] = True
        tmp.append(typed)
    return (tmp,failed)

def main():
    while True:
        sys.stdout.write("$ ")
        cmd = input().split(" ")
        match cmd[0]:
            case "exit":
                args = argparse(cmd[1:],[int])
                if args[1][1] == True or args[0][0][1] == False:
                    print("Argument failure")
                else:
                    exit(args[0][0][0])
            case "echo":
                if len(cmd[1:]) == 0:
                    print()
                else:
                    print(" ".join(cmd[1:]))
            case "type":
                path = os.environ["PATH"].split(":")
                cmds = {}
                for x in path:
                    for y in os.listdir(os.path.join(x)):
                        cmds[y] = os.path.join(x)
                args = argparse(cmd[1:],[str])
                if args[1][1] == True or args[0][0][1] == False:
                    print("Argument failure")
                else:
                    if args[0][0][0] in ["exit","echo","type"]:
                        print(f"{args[0][0][0]} is a shell builtin")
                    if args[0][0][0] in cmds.keys():
                        print(f"{args[0][0][0]} is {cmds[args[0][0][0]]}")
                    else:
                        print(f"{args[0][0][0]}: not found")
            case _:
                print(f"{' '.join(cmd)}: command not found")

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [June 25, 2025, 5:30pm UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623/3 "2025-06-25T17:30:02Z")

</div>

Hey @Zeviraty, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![Zeviraty](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/zeviraty/32/13507_2.png) [@Zeviraty](https://forum.codecrafters.io/u/Zeviraty)\
**Post date:** [June 25, 2025, 5:49pm UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623/4 "2025-06-25T17:49:09Z")

</div>

> **[GitHub - Zeviraty/shell-cc](https://github.com/Zeviraty/shell-cc)**
>
> Contribute to Zeviraty/shell-cc development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![EshaanAgg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/eshaanagg/32/399_2.png) [@EshaanAgg](https://forum.codecrafters.io/u/EshaanAgg)\
**Post date:** [June 26, 2025, 3:43am UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623/5 "2025-06-26T03:43:33Z")

</div>

The problem that you are facing is expected: the folders mentioned in PATH

- May not exist
- Maybe empty
- The current shell process may not have the appropriate access to read those directories

Thus using the ‘try to read, but if it fails then ignore silently’ approach is recommended for every folder.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [July 4, 2025, 1:32am UTC](https://forum.codecrafters.io/t/shell-python-cant-find-directories-shown-in-path/12623/8 "2025-07-04T01:32:11Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
