file_utils 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 84

file_utils

File utils is a collection of the helper classes for file system.

Includes the following helpers:

FileList

Intelligent search of files with reduced amount of operations of disk access.

FileUtils

The collection of the helper methods for file system.

Includes the following methods:

  • basename
  • chdir
  • dirempty
  • dirname
  • exclude
  • fullpath
  • getcwd
  • glob
  • include
  • mkdir
  • move
  • rename
  • rm
  • rmdir
  • symlink
  • testfile
  • touch
  • uptodate

FilePath

The collection of the helper methods for file path.

Includes the following methods:

  • expand
  • fullname

0.1.1

  • Minor cosmetic fixes

0.1.0

  • Adaptation to Dart 2.0

example/example.dart

import "dart:io";
import "package:file_utils/file_utils.dart";

void main() {
  // basename
  print("basename:");
  var path = FileUtils.getcwd();
  var name = FileUtils.basename(path);
  print("path: $path");
  print("name: $name");
  print("=============");

  // chdir
  print("chdir:");
  var save = FileUtils.getcwd();
  print("cwd: $save");

  FileUtils.chdir("..");
  path = FileUtils.getcwd();
  print("cwd: $path");

  FileUtils.chdir("~");
  path = FileUtils.getcwd();
  print("cwd: $path");

  FileUtils.chdir(save);
  path = FileUtils.getcwd();
  print("cwd: $path");
  print("=============");

  // dirempty
  print("dirempty:");

  var empty = FileUtils.dirempty(".");
  print("path: .");
  print("empty: $empty");

  FileUtils.mkdir(["temp"]);
  empty = FileUtils.dirempty("temp");
  print("path: temp");
  print("empty: $empty");
  FileUtils.rmdir(["temp"]);
  print("=============");

  // dirname
  print("dirname:");
  path = FileUtils.getcwd();
  name = FileUtils.dirname(path);
  print("path: $path");
  print("name: $name");
  print("=============");

  // exclude
  print("exclude:");
  var files = FileUtils.glob("*.yaml");
  files = FileUtils.exclude(files, "*spec.yaml");
  print("exclude: *spec.yaml");
  print("files: $files");
  print("=============");

  // fullpath
  print("fullpath:");
  path = FileUtils.fullpath("../file_utils");
  print("name: ../file_utils");
  print("path: $path");

  // getcwd
  print("getcwd:");
  path = FileUtils.getcwd();
  print("cwd: $path");
  print("=============");

  // glob
  print("glob:");  
  var dirs = FileUtils.glob("*/");
  dirs = dirs.map((e) => FileUtils.basename(e)).toList();
  print("glob: $dirs");  
  print("=============");

  // include
  print("include:");
  files = FileUtils.glob("*.yaml");
  files = FileUtils.include(files, "*spec.yaml");
  print("include: *spec.yaml");
  print("files: $files");
  print("=============");

  // mkdir
  print("mkdir:");
  FileUtils.mkdir(["temp"]);
  FileUtils.chdir("temp");
  path = FileUtils.getcwd();
  print("cwd: $path");
  FileUtils.chdir("..");
  FileUtils.rmdir(["temp"]);
  print("=============");

  // move
  print("move:");
  FileUtils.mkdir(["temp1", "temp2"]);
  FileUtils.touch(["temp1/file.txt"]);
  FileUtils.move(["temp1/*.txt"], "temp2");

  files = FileUtils.glob("temp1/*.txt");
  files = files.map((e) => FileUtils.basename(e)).toList();
  print("path: temp1");
  print("files: $files");

  files = FileUtils.glob("temp2/*.txt");
  files = files.map((e) => FileUtils.basename(e)).toList();
  print("path: temp2");
  print("files: $files");

  FileUtils.rm(["temp1", "temp2"], recursive: true);

  // rename
  print("rename:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.rename("temp1", "temp2");
  FileUtils.chdir("temp2");
  path = FileUtils.getcwd();
  print("cwd: $path");
  FileUtils.chdir("..");
  FileUtils.rmdir(["temp2"]);
  print("=============");

  // rm
  print("rm:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.chdir("temp1");
  FileUtils.touch(["temp1/file.txt"]);  
  FileUtils.rm(["temp1"], recursive: true);
  print("=============");

  // rmdir
  print("rmdir:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.chdir("temp1");
  FileUtils.chdir("..");
  FileUtils.rmdir(["temp1"]);
  print("=============");

  // symlink
  print("symlink:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.symlink("temp1", "temp2");
  FileUtils.chdir("temp2");
  path = FileUtils.getcwd();
  print("cwd: $path");
  FileUtils.chdir("..");
  FileUtils.rm(["temp1", "temp2"], recursive: true);
  print("=============");

  // testfile
  print("testfile:");
  FileUtils.mkdir(["temp1"]);
  var exists = FileUtils.testfile("temp1", "directory");
  print("path: temp1");
  print("exists: $exists");
  FileUtils.rmdir(["temp1"]);
  print("=============");

  // touch
  print("touch:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.touch(["temp1/file1.txt"]);
  exists = FileUtils.testfile("temp1/file1.txt", "file");
  print("path: temp1/file1.txt");
  print("exists: $exists");
  FileUtils.rm(["temp1"], recursive: true);
  print("=============");

  // uptodate
  print("uptodate:");
  FileUtils.mkdir(["temp1"]);
  FileUtils.touch(["temp1/file1.txt"]);
  print("wait...");
  sleep(new Duration(milliseconds: 1000));
  FileUtils.touch(["temp1/file2.txt"]);
  var uptodate = FileUtils.uptodate("temp1/file1.txt", ["temp1/file2.txt"]);
  print("path: temp1/file1.txt");
  print("uptodate: $uptodate");
  FileUtils.rm(["temp1"], recursive: true);
  print("=============");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  file_utils: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:file_utils/file_utils.dart';
  
Version Uploaded Documentation Archive
0.1.1 Aug 14, 2018 Go to the documentation of file_utils 0.1.1 Download file_utils 0.1.1 archive
0.1.0 Aug 14, 2018 Go to the documentation of file_utils 0.1.0 Download file_utils 0.1.0 archive
0.0.23 Jul 15, 2014 Go to the documentation of file_utils 0.0.23 Download file_utils 0.0.23 archive
0.0.22 May 8, 2014 Go to the documentation of file_utils 0.0.22 Download file_utils 0.0.22 archive
0.0.21 May 7, 2014 Go to the documentation of file_utils 0.0.21 Download file_utils 0.0.21 archive
0.0.20 May 7, 2014 Go to the documentation of file_utils 0.0.20 Download file_utils 0.0.20 archive
0.0.19 May 6, 2014 Go to the documentation of file_utils 0.0.19 Download file_utils 0.0.19 archive
0.0.18 May 5, 2014 Go to the documentation of file_utils 0.0.18 Download file_utils 0.0.18 archive
0.0.17 May 5, 2014 Go to the documentation of file_utils 0.0.17 Download file_utils 0.0.17 archive
0.0.16 May 3, 2014 Go to the documentation of file_utils 0.0.16 Download file_utils 0.0.16 archive

All 24 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, other

Primary library: package:file_utils/file_utils.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
globbing ^0.2.0 0.2.0
path ^1.6.2 1.6.2
Dev dependencies
test any