getUserDirectory function

Directory? getUserDirectory(
  1. String dirName
)

Gets the xdg user directory named by dirName.

Use getUserDirectoryNames to find out the list of available names.

If the xdg-user-dir executable is not present this returns null.

Implementation

Directory? getUserDirectory(String dirName) {
  final ProcessResult result;
  try {
    result = _processRunner.runSync(
      'xdg-user-dir',
      <String>[dirName],
      stdoutEncoding: utf8,
    );
  } on ProcessException catch (e) {
    // Silently return null if it's missing, otherwise pass the exception up.
    if (e.errorCode == _noSuchFileError) {
      return null;
    }
    rethrow;
  }
  final String path = (result.stdout as String).split('\n')[0];
  return Directory(path);
}