It looks to me as File.exists claims that directories doesn't exist. I know a directory isn't a file, but I think it would be handy to have one operation to determine if a file name refers to something that exists or not.
I agree this is a useful operation, but the current behavior is also useful (and being used in pub). I'm up for adding this as a new operation, but I wouldn't want to change the current semantics of File.exists.
_This comment was originally written by @seaneagan_
if there were a separate Path object on Files and Directories as has been suggested, then that could have an exists methods with the semantics requested here.
_This comment was originally written by @seaneagan_
Or have a common base interface for File and Directory, and have it's exists method return true if anything exists at all:
interface FileNode {
String path;
void fullPath(void callback(String fullPath));
String fullPathSync();
void create(void callback());
void createSync();
void delete(void callback());
void deleteSync();
void exists(void callback(bool));
bool existsSync();
}
interface File extends FileNode //...
interface Directory extends FileNode //...
_This comment was originally written by @ahmetaa_
Perhaps a Path class as in Java and C# can resolve this?
_Added this to the Later milestone._
We've landed some changes, so now:
new File(path).existsSync() == true, iff path is file, or link to file.
new Directory(path).existsSync() == true, iff path is directory, or link to directory.
new Link(path).existsSync() == true, iff path link.
To query just once, you can use FileSystemEntity.typeSync(path) != FileSystemEntityType.NOT_FOUND.
_Added Fixed label._
I'm not convinced this is a good solution. I think you have made the common operation hard, and the uncommon operation easy.
I don't think it would be a bad thing to add bool FileSystemEntity.exists(path).
I'm not sure what it should report on broken links, though. Probably true.
_Removed Area-IO label._
_Added Area-Library, Library-IO labels._
FileSystemEntityType.NOT_FOUND is deprecated and FileSystemEntityType.notFound should be used.
Most helpful comment
We've landed some changes, so now:
new File(path).existsSync() == true, iff path is file, or link to file.
new Directory(path).existsSync() == true, iff path is directory, or link to directory.
new Link(path).existsSync() == true, iff path link.
To query just once, you can use FileSystemEntity.typeSync(path) != FileSystemEntityType.NOT_FOUND.
_Added Fixed label._