Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,5 @@ submission = Submission(

result = judge0.run(submissions=submission)
print(result.stdout)

matches = [f for f in result.post_execution_filesystem if f.name == "my_dir2/my_file2.txt"]
f = matches[0] if matches else None
print(f)
print(result.post_execution_filesystem.find("./my_dir2/my_file2.txt"))
```
21 changes: 21 additions & 0 deletions src/judge0/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ def encode(self) -> bytes:
zip_file.writestr(file.name, file.content)
return zip_buffer.getvalue()

def find(self, name: str) -> Optional[File]:
"""Find file by name in Filesystem object.

Parameters
----------
name : str
File name to find.

Returns
-------
File or None
Found File object or None if not found.
"""
if name.startswith("./"):
name = name[2:]
elif name.startswith("/"):
name = name[1:]

matches = [f for f in self.files if f.name == name]
return matches[0] if matches else None

def __str__(self) -> str:
"""Create string representation of Filesystem object."""
return b64encode(self.encode()).decode()
Expand Down