dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

Provide path manipulation support in dart:io #1618

Closed munificent closed 9 years ago

munificent commented 12 years ago

Given a File object, it's useful to get its containing Directory. Ideally:

  var file = new File(...);   Directory dir = file.directory;

Path manipulation functions (dirname, basename, etc.) in general would be useful.

madsager commented 12 years ago

Removed Type-Defect label. Added Type-Enhancement, Accepted labels.

madsager commented 12 years ago

cc @sgjesse. Set owner to @whesse.

madsager commented 12 years ago

Stealing this back. I'll add File.directory() and File.directorySync() methods to the File interface.


cc @whesse. Set owner to @madsager. Added Started label.

madsager commented 12 years ago

Access to the containing directory for a file is now available. I agree that we need more path manipulation functionality. We were considering whether or not it would make sense to perform those manipulations using URIs. Extend the File interface with the ability to get a file URI from a file and have a constructor that takes a File URI. The extend the URI library with nice manipulation functionality. This is still a bit in the air but it is definitely on our radar.


Added Fixed label.

munificent commented 12 years ago

Why are there sync and async versions, and why aren't they getters? The directory path for a file is a simple easy-to-calculate property of the file isn't it?

madsager commented 12 years ago

It requires native calls and inspection of the file system. If your file system is slow NFS drive or something similar that could block the main thread for a while. I'm actually still in favor of not having any sync methods in the API at all (but we have the sync methods because I realize that for parts of your code not having them can be pretty hostile to users).

munificent commented 12 years ago

I don't understand. Isn't this just a string operation on the path? If not, why not?

madsager commented 12 years ago

Because we use the system to deal with '/' and '\' differences and the like. It probably could be implemented as a pure string operation but there are many cases to consider that the system handles for you already.

munificent commented 12 years ago

So can I use this to manipulate fictitious paths to files that don't exist?

madsager commented 12 years ago

At this point this only works for files that exist. Is that too restrictive?

munificent commented 12 years ago

Yes, it is. I think there's two broad classes of functionality I want:

  1. An API for making it pleasant to work with file paths. Things like "get the extension", "get the basename", "get the parent directory", "join a series of paths", and possibly even canonicalization.
  2. An API for accessing the file system: open a file at a path, traverse the contents of a directory, see if a file exists.

The former should explicitly not require those paths to exist or even be meaningful: programs often manipulate paths (or URLs) that don't correspond to the file system the program is running on. The latter, obviously, should. :)

madsager commented 12 years ago

Bob, let me keep this bug open and change it to a bug path manipulation.

What do you think of the idea I alluded to above that path manipulation (without access to the file system) could be done as part of a URI library with lots of functionality for File URIs?


Added Accepted label.

madsager commented 12 years ago

Changed the title to: "Provide path manipulation support in dart:io".

munificent commented 12 years ago

I think that might work? I'd have to see the actual API to get a feel for how it would go in practice. It seems like there's stuff that wouldn't make sense for URIs that we would still want, though, right? Things like "extension" aren't something I would expect in a URI library but I would in a path one.

Even though there is likely to be overlap between the two, it may be more usable to have two separate libraries. My hunch is that users are mentally in the mode of either "I'm working with file paths" or "I'm working with URIs" and would expect to find a library for each. Having to know to use the URI library when they're thinking "path" might be confusing.

madsager commented 12 years ago

Set owner to @whesse.

madsager commented 12 years ago

Added this to the M1 milestone.

madsager commented 12 years ago

dart:io has simple path support. Let's close this bug report and open new ones for individual feature requests.


Added Fixed label.

kevmoo commented 10 years ago

Removed Area-IO label. Added Area-Library, Library-IO labels.