Python "NotADirectoryError: [Errno 20]" in CI
NotADirectoryError: [Errno 20] Not a directory is raised when an operation expects a directory in a path but finds a regular file there, for example listing or traversing through a file.
What this error means
A step fails with "NotADirectoryError: [Errno 20] Not a directory: 'archive.zip/inner'" while listing or joining a path.
python
NotADirectoryError: [Errno 20] Not a directory: 'data.tar/contents'Common causes
Treating an archive or file as a directory
Code appended a child path to something that is a file (a tar/zip), so traversal fails.
A name collision where a dir was expected
A previous step wrote a file with the same name the code now tries to enter as a folder.
How to fix it
Verify the path is a directory before traversing
- Check
path.is_dir()before listing or joining child names. - For archives, extract to a temp directory and traverse the extraction.
- Resolve name collisions so directories and files do not share a name.
Python
import pathlib
p = pathlib.Path(target)
if not p.is_dir():
raise NotADirectoryError(f"expected a directory: {p}")How to prevent it
- Check is_dir() before directory operations.
- Extract archives before traversing their contents.
- Avoid file/dir name collisions in build output.
Related guides
Python "IsADirectoryError: [Errno 21]" in CIFix "IsADirectoryError: [Errno 21] Is a directory" in CI - code tried to open or read a path as a file but it…
Python "FileExistsError: [Errno 17]" in CIFix "FileExistsError: [Errno 17] File exists" in CI - mkdir or an exclusive open failed because the target al…
Python "PermissionError: [Errno 13] Permission denied" in CIFix "PermissionError: [Errno 13] Permission denied" in CI - the process tried to read, write, or execute a pa…