validatePath static method

void validatePath(
  1. String path
)

Validates that a path is valid and accessible

Throws ArgumentError if the path is invalid Throws FileSystemException if the path is not accessible

Implementation

static void validatePath(String path) {
  if (path.isEmpty) {
    throw ArgumentError('Path cannot be empty');
  }

  // Check for invalid characters (basic validation)
  if (path.contains('\x00')) {
    throw ArgumentError('Path contains null character');
  }

  // Normalize the path to handle relative paths and redundant separators
  final normalizedPath = p.normalize(path);

  // Check if the path is absolute or relative
  if (p.isAbsolute(normalizedPath)) {
    // For absolute paths, check if parent directory exists
    final parentDir = p.dirname(normalizedPath);
    if (!Directory(parentDir).existsSync()) {
      throw FileSystemException('Parent directory does not exist', parentDir);
    }
  }

  // Additional validation can be added here as needed
}