Skip to content

Instantly share code, notes, and snippets.

@kasperpeulen
Created August 2, 2015 23:57
Show Gist options
  • Select an option

  • Save kasperpeulen/048c53b2e7c779a2573b to your computer and use it in GitHub Desktop.

Select an option

Save kasperpeulen/048c53b2e7c779a2573b to your computer and use it in GitHub Desktop.
Finding the type of a filesystem object.
import 'dart:io';
main() async {
// List the contents of the system temp directory.
await for (FileSystemEntity entity in Directory.systemTemp.list(recursive: true, followLinks: false)) {
// Get the type of the FileSystemEntity
FileSystemEntityType type = await FileSystemEntity.type(entity.path);
// Give the type a label
String label = () {
switch (type) {
case FileSystemEntityType.DIRECTORY:
return 'D';
case FileSystemEntityType.FILE:
return 'F';
case FileSystemEntityType.LINK:
return 'L';
default:
return 'UKNOWN';
}
}();
// Print the label
print('$label: ${entity.path}');
}
}
name: dart.io_FileSystemEntity.type
description: |
Finding the type of a filesystem object.
Use the FileSystemEntity.type() method to get the type of a file system object. This method is inherited by File, Directory, and Link.
homepage: https://gist.github.com/kasperpeulen/048c53b2e7c779a2573b
environment:
sdk: '>=1.11.0 <2.0.0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment