Appearance
File System API Reference
📁 Related Tutorial
- File Operations Guide - Complete guide to file system operations
Overview
The File System module provides comprehensive file and directory operations within the AGB cloud environment. It supports file upload, download, and manipulation.
FileChangeEvent
python
class FileChangeEvent()Represents a single file change event.
FileInfoResult
python
class FileInfoResult(ApiResponse)Result of file info operations.
DirectoryListResult
python
class DirectoryListResult(ApiResponse)Result of directory listing operations.
FileContentResult
python
class FileContentResult(ApiResponse)Result of file read operations.
MultipleFileContentResult
python
class MultipleFileContentResult(ApiResponse)Result of multiple file read operations.
FileSearchResult
python
class FileSearchResult(ApiResponse)Result of file search operations.
FileChangeResult
python
class FileChangeResult(ApiResponse)Result of file change detection operations.
has_changes
python
def has_changes() -> boolCheck if there are any file changes.
get_modified_files
python
def get_modified_files() -> List[str]Get list of modified file paths.
get_created_files
python
def get_created_files() -> List[str]Get list of created file paths.
get_deleted_files
python
def get_deleted_files() -> List[str]Get list of deleted file paths.
FileSystem
python
class FileSystem(BaseService)FileSystem provides file system operations for the session.
DEFAULT_CHUNK_SIZE
python
DEFAULT_CHUNK_SIZE = 50 * 1024create_directory
python
def create_directory(path: str) -> BoolResultCreate a new directory at the specified path.
Arguments:
pathstr - The path of the directory to create.
Returns:
BoolResult: Result object containing success status and error message if
any.
edit_file
python
def edit_file(path: str,
edits: List[Dict[str, str]],
dry_run: bool = False) -> BoolResultEdit a file by replacing occurrences of oldText with newText.
Arguments:
pathstr - The path of the file to edit.editsList[Dict[str, str]] - A list of dictionaries specifying oldText and newText.dry_runbool - If True, preview changes without applying them. Defaults to False.
Returns:
BoolResult: Result object containing success status and error message if
any.
get_file_info
python
def get_file_info(path: str) -> FileInfoResultGet information about a file or directory.
Arguments:
pathstr - The path of the file or directory to inspect.
Returns:
FileInfoResult: Result object containing file info and error message if any.
list_directory
python
def list_directory(path: str) -> DirectoryListResultList the contents of a directory.
Arguments:
pathstr - The path of the directory to list.
Returns:
DirectoryListResult: Result object containing directory entries and error
message if any.
move_file
python
def move_file(source: str, destination: str) -> BoolResultMove a file or directory from source path to destination path.
Arguments:
sourcestr - The source path of the file or directory.destinationstr - The destination path.
Returns:
BoolResult: Result object containing success status and error message if
any.
read_file
python
def read_file(path: str) -> FileContentResultRead the contents of a file.
Arguments:
pathstr - The path of the file to read.
Returns:
FileContentResult: Result object containing file content and error message
if any.
write_file
python
def write_file(path: str, content: str, mode: str = "overwrite") -> BoolResultWrite content to a file. Automatically handles large files by chunking.
Arguments:
pathstr - The path of the file to write.contentstr - The content to write to the file.modestr - The write mode ("overwrite" or "append"). Defaults to "overwrite".
Returns:
BoolResult: Result object containing success status and error message if
any.
read_multiple_files
python
def read_multiple_files(paths: List[str]) -> MultipleFileContentResultRead the contents of multiple files at once.
Arguments:
pathsList[str] - A list of file paths to read.
Returns:
MultipleFileContentResult: Result object containing a dictionary mapping
file paths to contents, and error message if any.
search_files
python
def search_files(
path: str,
pattern: str,
exclude_patterns: Optional[List[str]] = None) -> FileSearchResultSearch for files in the specified path using a pattern.
Arguments:
pathstr - The base directory path to search in.patternstr - The glob pattern to search for.exclude_patternsOptional[List[str]] - Optional list of patterns to exclude from the search. Defaults to None.
Returns:
FileSearchResult: Result object containing matching file paths and error
message if any.
watch_directory
python
def watch_directory(
path: str,
callback: Callable[[List[FileChangeEvent]], None],
interval: float = 1.0,
stop_event: Optional[threading.Event] = None) -> threading.ThreadWatch a directory for file changes and call the callback function when changes occur.
Arguments:
pathstr - The directory path to monitor for file changes.callbackCallable[[List[FileChangeEvent]], None] - Callback function that will be called with a list of FileChangeEvent objects when changes are detected.intervalfloat - Polling interval in seconds. Defaults to 1.0.stop_eventOptional[threading.Event] - Optional threading.Event to stop the monitoring. If not provided, a new Event will be created and returned via the thread object. Defaults to None.
Returns:
threading.Thread: The monitoring thread. Call thread.start() to begin monitoring.
Use the thread's stop_event attribute to stop monitoring.
Best Practices
- Always check file permissions before operations
- Use appropriate file paths and handle path separators correctly
- Clean up temporary files after operations
- Handle file operation errors gracefully
- Use streaming for large file operations
Related Resources
Documentation generated automatically from source code using pydoc-markdown.