FileHelper class

File system operation helpers for CLI commands.

Provides utilities for file/directory operations, YAML reading/writing, and project root detection.

Usage

// Check if file exists
if (FileHelper.fileExists('/path/to/file.txt')) {
  final content = FileHelper.readFile('/path/to/file.txt');
}

// Find project root
final projectRoot = FileHelper.findProjectRoot();

// Read YAML file
final config = FileHelper.readYamlFile('config.yaml');

Constructors

FileHelper()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

copyFile(String source, String destination) → void
Copy a file from source to destination.
deleteFile(String filePath) → void
Delete a file at the given path.
directoryExists(String dirPath) bool
Check if a directory exists at the given path.
ensureDirectoryExists(String dirPath) → void
Ensure a directory exists at the given path.
fileExists(String filePath) bool
Check if a file exists at the given path.
findProjectRoot({String? startFrom}) String
Find the project root directory by traversing up to find pubspec.yaml.
getRelativePath(String from, String to) String
Compute the relative path from from to to.
readFile(String filePath) String
Read the contents of a file as a string.
readYamlFile(String filePath) Map<String, dynamic>
Read a YAML file and parse it to a Map.
writeFile(String filePath, String content) → void
Write content to a file.
writeYamlFile(String filePath, Map<String, dynamic> data) → void
Write a Map to a YAML file.