pub struct FolderHandler { /* private fields */ }
Expand description
Handler for folder operations
Provides methods for listing, creating, searching, and managing folders (directories) in Files.com.
Implementations§
Source§impl FolderHandler
impl FolderHandler
Sourcepub fn new(client: FilesClient) -> Self
pub fn new(client: FilesClient) -> Self
Sourcepub async fn list_folder(
&self,
path: &str,
per_page: Option<i32>,
cursor: Option<String>,
) -> Result<(Vec<FileEntity>, PaginationInfo)>
pub async fn list_folder( &self, path: &str, per_page: Option<i32>, cursor: Option<String>, ) -> Result<(Vec<FileEntity>, PaginationInfo)>
List folder contents
Returns files and subdirectories within the specified folder.
§Arguments
path
- Folder path to list (empty string for root)per_page
- Number of items per page (optional, max 10,000)cursor
- Pagination cursor (optional)
§Returns
Returns a tuple of (files, pagination_info)
§Examples
use files_sdk::{FilesClient, FolderHandler};
let client = FilesClient::builder()
.api_key("your-api-key")
.build()?;
let handler = FolderHandler::new(client);
let (files, pagination) = handler.list_folder("/", None, None).await?;
for file in files {
println!("{}: {}", file.file_type.unwrap_or_default(), file.path.unwrap_or_default());
}
if pagination.has_next() {
println!("More results available");
}
Sourcepub async fn list_folder_all(&self, path: &str) -> Result<Vec<FileEntity>>
pub async fn list_folder_all(&self, path: &str) -> Result<Vec<FileEntity>>
List all folder contents (auto-pagination)
Automatically handles pagination to retrieve all items in a folder.
§Arguments
path
- Folder path to list
§Examples
let handler = FolderHandler::new(client);
let all_files = handler.list_folder_all("/uploads").await?;
println!("Total files: {}", all_files.len());
Sourcepub fn list_stream(
&self,
path: &str,
per_page: Option<i32>,
) -> impl Stream<Item = Result<FileEntity>> + '_
pub fn list_stream( &self, path: &str, per_page: Option<i32>, ) -> impl Stream<Item = Result<FileEntity>> + '_
Stream folder contents with automatic pagination
Returns a stream that automatically handles pagination, yielding
individual files as they are fetched. This is more memory-efficient
than list_folder_all()
for large directories.
§Arguments
path
- Folder path to listper_page
- Number of items per page (optional, default 1000)
§Examples
let handler = FolderHandler::new(client);
let stream = handler.list_stream("/uploads", Some(100));
tokio::pin!(stream);
while let Some(file) = stream.next().await {
let file = file?;
println!("{}", file.path.unwrap_or_default());
}
Sourcepub async fn create_folder(
&self,
path: &str,
mkdir_parents: bool,
) -> Result<FileEntity>
pub async fn create_folder( &self, path: &str, mkdir_parents: bool, ) -> Result<FileEntity>
Create a new folder
Note: In Files.com, folders are created implicitly when uploading files
with mkdir_parents=true
. This method creates an empty folder.
§Arguments
path
- Folder path to createmkdir_parents
- Create parent directories if they don’t exist
§Examples
let handler = FolderHandler::new(client);
handler.create_folder("/new/folder", true).await?;
Sourcepub async fn search_folder(
&self,
path: &str,
search: &str,
per_page: Option<i32>,
) -> Result<(Vec<FileEntity>, PaginationInfo)>
pub async fn search_folder( &self, path: &str, search: &str, per_page: Option<i32>, ) -> Result<(Vec<FileEntity>, PaginationInfo)>
Search for files within a folder
§Arguments
path
- Folder path to search insearch
- Search query stringper_page
- Number of results per page (optional)
§Examples
let handler = FolderHandler::new(client);
let (results, _) = handler.search_folder("/", "report", None).await?;
println!("Found {} files", results.len());
Trait Implementations§
Source§impl Clone for FolderHandler
impl Clone for FolderHandler
Source§fn clone(&self) -> FolderHandler
fn clone(&self) -> FolderHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more