Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Cookbook: Dart by Example' page issue #685

Closed
Herohtar opened this issue Mar 19, 2018 · 1 comment
Closed

'Cookbook: Dart by Example' page issue #685

Herohtar opened this issue Mar 19, 2018 · 1 comment

Comments

@Herohtar
Copy link

Herohtar commented Mar 19, 2018

Per this SO question, the Renaming a file, directory, or symlink example is wrong. The example code is:

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}');
}

It incorrectly says that the original File object will have the updated path, when the API for rename() shows that it actually returns a new File instance for the renamed file.

The last lines should actually be something like:

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

// Prints path ending with `bar.txt`.
print('The path is ${renamedFile.path}');
@kwalrath
Copy link
Contributor

Thanks very much for filing this issue.

Unfortunately, we're planning to remove the cookbook, since it's not well tested and has been rotting. That said, the repo it's taken from is open source, and it wouldn't hurt to fix the sample there:

https://github.com/dart-lang/dart-samples/blob/master/dart_io_mini_samples/example/files_directories_and_symlinks/renaming_a_file_directory_or_symlink.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants