path_type 0.3.0 copy "path_type: ^0.3.0" to clipboard
path_type: ^0.3.0 copied to clipboard

A path type providing a type-safe and cross-platform path abstraction for managing and manipulating file paths, supporting both POSIX and Windows file systems.

example/main.dart

import 'package:path_type/posix.dart';
import 'package:rust_core/option.dart';

void main() {
  var path = Path('/foo/bar/baz.txt');

  print('File name: ${path.fileName()}'); // Output: baz.txt
  print('Extension: ${path.extension()}'); // Output: txt
  print('Is absolute: ${path.isAbsolute()}'); // Output: true

  var parent = path.parent();
  if (parent.isSome()) {
    print('Parent: ${parent.unwrap()}'); // Output: /foo/bar
  }

  var newPath = path.withExtension('md');
  print('New path with extension: $newPath'); // Output: /foo/bar/baz.md

  path = Path('/foo/bar/baz.txt');

  if (path.exists()) {
    var metadata = path.metadata();
    print('File size: ${metadata.size}');
    print('Last modified: ${metadata.modified}');
  } else {
    print('Path does not exist.');
  }

  path = Path('/foo/bar/baz.txt');

  for (var ancestor in path.ancestors()) {
    print(ancestor);
    // Output:
    // /foo/bar/baz.txt
    // /foo/bar
    // /foo
    // /
  }

  path = Path('/foo/bar/baz.txt');
  var components = path.components().toList();

  for (var component in components) {
    print(component); // Output: /, foo, bar, baz.txt
  }
}
3
likes
0
pub points
58%
popularity

Publisher

verified publishervoyver.com

A path type providing a type-safe and cross-platform path abstraction for managing and manipulating file paths, supporting both POSIX and Windows file systems.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

path, rust_core

More

Packages that depend on path_type