/

File Listing & Indexing

ByteHide Storage provides powerful methods to list and organize your files efficiently.

Basic Listing

List Directory Contents

Get files in a directory:

// List root directory
var rootFiles = await storage.ListAsync("/");

// List specific directory
var imageFiles = await storage
    .In("images")
    .ListAsync();

// List with full paths
var files = await storage
    .In("documents/reports")
    .ListAsync();

foreach (var file in files)
{
    Console.WriteLine($"Path: {file.FullPath}");
}

Recursive Listing

List files in all subdirectories:

// Get all files recursively
var allFiles = await storage
    .In("documents")
    .ListAsync(recursive: true);

// Process recursive results
foreach (var file in allFiles)
{
    Console.WriteLine($"Directory: {file.Directory}");
    Console.WriteLine($"Name: {file.Name}");
}

Advanced Listing

Directory Navigation

Navigate through directory structure:

// List files in nested directories
var reports = await storage
    .In("company")
    .In("finance")
    .In("2024")
    .ListAsync();

// Get parent directory contents
var parentFiles = await storage
    .In("documents/reports/2024")
    .In("..")
    .ListAsync();

File Filtering

Filter files based on properties:

var files = await storage
    .In("documents")
    .ListAsync();

// Filter by type
var pdfFiles = files.Where(f => f.Name.EndsWith(".pdf"));

// Filter by size
var largeFiles = files.Where(f => f.Size > 1024 * 1024); // > 1MB

// Filter by security
var encryptedFiles = files.Where(f => f.IsEncrypted);
var publicFiles = files.Where(f => f.IsPublic);

Tag-Based Organization

Add and filter files using tags:

// Add multiple tags when uploading
await storage
    .SetTags("report", "finance", "2024")
    .Set("reports/q1.pdf", reportData);

// Add tags to files in a directory
var taggedStorage = storage
    .In("documents/contracts")
    .SetTags("legal", "confidential");

Search files directly by tags:

// Search files with specific tag
var financeFiles = await storage.SearchByTag("finance");

// Search in specific directory
var legalDocs = await storage
    .In("documents")
    .SearchByTag("legal");

// Combine multiple tags in search
var reports2024 = await storage.SearchByTag("report", "2024");

// Search with tag in nested directories
var confidentialContracts = await storage
    .In("legal/contracts")
    .SearchByTag("confidential");

Tag Filtering

Filter already listed files by tags:

// Get all files and filter (use SearchByTag instead for better performance)
var files = await storage
    .In("documents")
    .ListAsync();

// Filter by tags
var financeFiles = files.Where(f => f.ContainsTag("finance"));
var reports2024 = files
    .Where(f => f.ContainsTag("report"))
    .Where(f => f.ContainsTag("2024"));

// Combine tags with other filters
var confidentialPdfs = files
    .Where(f => f.ContainsTag("confidential"))
    .Where(f => f.Name.EndsWith(".pdf"));

Performance Tips

  • Use SearchByTag() when you only need files with specific tags
  • Use ListAsync() with ContainsTag() when you need to combine tag filtering with other criteria
  • SearchByTag() is more efficient for large directories

Tag Best Practices

  • Use consistent tag naming conventions
  • Consider creating a tag hierarchy (e.g., "department:finance", "year:2024")
  • Combine tags with directory structure for better organization
  • Use tags for cross-cutting categories that span multiple directories

Organization

Directory Structure

Organize files by type and date:

// List files by type
await storage
    .In("images")
    .In("2024")
    .In("Q1")
    .ListAsync();

// List files by department
await storage
    .In("departments")
    .In("marketing")
    .In("assets")
    .ListAsync();

Best Practices

  • Use consistent directory structures
  • Keep directory depths manageable
  • Consider using date-based organization for time-sensitive files
  • Use meaningful directory names

Performance Considerations

Efficient Listing

Optimize listing operations:

// List specific directory instead of recursive when possible
var currentFiles = await storage
    .In("current")
    .ListAsync();

// Cache results if needed frequently
var cachedFiles = await storage
    .In("static-content")
    .ListAsync();

Large Directories

When dealing with directories containing many files:

  • Avoid deep recursive listings when possible
  • Consider implementing pagination
  • Cache results when appropriate
Previous
File Metadata & Information