重命名文件,目录,链接

2028次阅读  |  发布于5年以前

重命名文件,目录,链接

Use the FileSystemEntity rename() method to change the name of a file, directory or symlink. This method is inherited by File, Directory, and Link.

import 'dart:io';

main() async {
  // Get the system temp directory.
  var systemTempDir = Directory.systemTemp;

  // Create a file.
  var file = await new File('${systemTempDir.path}/foo.txt').create();

  // Prints path ending with `foo.txt`.
  print('The path is ${file.path}');

  // Rename the file.
  await file.rename('${systemTempDir.path}/bar.txt');

  // Prints path ending with `bar.txt`.
  print('The path is ${file.path}');
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8