Directory Management
Learn how to effectively manage and organize your storage directories for better resource organization.
Directory Operations
Working with Directories
Use the fluent In()
method to work within specific directories:
// Chain multiple In() calls for nested directories
await storage
.In("documents")
.In("reports")
.In("2024")
.Set("january.pdf", reportData);
// Equivalent to
await storage
.In("documents/reports/2024")
.Set("january.pdf", reportData);
// Or
await storage.Set("documents/reports/2024/january.pdf", reportData);
// Build paths dynamically
string year = "2024";
string month = "january";
await storage
.In("documents")
.In("reports")
.In(year)
.In(month)
.Set("report.pdf", reportData);
Directory Listing
List contents of directories:
// List root directory
var rootFiles = await storage.ListAsync("/");
// List nested directory using chained In()
var reports = await storage
.In("documents")
.In("reports")
.ListAsync();
// Recursive listing from specific directory
var allFiles = await storage
.In("documents")
.ListAsync(recursive: true);
Directory Structure
Path Conventions
ByteHide Storage supports both chained In()
calls and forward slashes for paths:
// Using chained In() calls (recommended for dynamic paths)
storage
.In("company")
.In("department")
.In("team");
// Using single In() with forward slashes
storage.In("company/department/team");
// Both approaches are equivalent
Nested Structures
Create and use nested directory structures with fluent syntax:
// Build complex paths fluently
var projectStorage = storage
.In("company")
.In("department")
.In("team")
.In("project");
// Combine with other operations
await storage
.In("assets")
.In("images")
.In("profiles")
.Compress()
.FromFile("avatar.png", "local/avatar.png");
Directory Context
Maintaining Context
Directory context is maintained and can be extended:
// Create base context
var companyFiles = storage.In("company");
// Extend the context
var departmentFiles = companyFiles.In("department");
var teamFiles = departmentFiles.In("team");
// Each context maintains its path
await companyFiles.Set("company-wide.pdf", companyData);
await departmentFiles.Set("dept-policy.pdf", deptData);
await teamFiles.Set("team-notes.pdf", teamData);
Combining with Features
Directory context works fluently with all storage features:
// Build secure storage path with multiple operations
var secureStorage = storage
.In("secure")
.In("confidential")
.Encrypt()
.Compress();
// Context maintains all settings
await secureStorage
.In("2024")
.In("Q1")
.Set("report.pdf", reportData);
Best Practices
- Use chained
In()
calls for dynamic path construction - Keep directory structures logical and organized
- Leverage the fluent interface for readable code
- Consider using variables for dynamic path segments