You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FileSystemAccess.fileExists returns true for directory as well #1534
This is completely contrary to virtually every other programming language or framework, not only Java or Node.js.
The various "exists" functions check for existance regardless of file type, and directories are just files of a special type. Typically you check that at the second stage.
So, this breaks intuitively expected behaviour and possibly also some already existing code out there.
Well, I was afraid of this. :) Possible option will be to restore the original behavior and provide additional optional parameter with true as default value:
If you want to implement both variants for convenience, it might be more consistent to have 3 different methods, like:
static exists(path: string): boolean; // classic behaviour
static isExistingRegularFile(path: string): boolean; // true if plain file
static isExistingFolder(path: string): boolean; // true if folder
@enchev Given the default behavior on Node, iOS and Android is to return true for a simple exists check then any arbitrary parameters/methods added to the API seem artificial to me. If it is important for the user to check for a file explicitly he may do something like
if(File.exists(path) && !Folder.exists(path)) {
}
So, my vote goes for reverting the behavior to its previous state.
@atanasovg Thanks for expanding my horizon. I admit I only checked with Java, PHP, Python, Ruby, Perl, classic C and a couple of web frameworks, which all seem to rely on the stat() system call.
So make that "a majority of programming languages and frameworks, especially in the context of web development" ;-)
I suppose reverting is fine. Having said that, like most of the NS team, my
experience is with .NET too and I find this result surprising given my
experience. I guess it feels very *nixy, which is fine if that is what I
was expecting. It makes sense to revert if that's how Node.js does it.
Perhaps a compromise would be to enhance the documentation to point out the
actual behaviour?
Activity
enchev commentedon Feb 11, 2016
Hey folks,
It seems we were too fast! :)
File.existswill return true for folder in both iOS and Node.js as well. It seems that this is the expected behavior![UPDATE]. Finally we've decided that it will be better to return false on folder!
cokobware commentedon Feb 17, 2016
Thanks for fixing this guys!
lhitc commentedon Feb 17, 2016
This is completely contrary to virtually every other programming language or framework, not only Java or Node.js.
The various "exists" functions check for existance regardless of file type, and directories are just files of a special type. Typically you check that at the second stage.
So, this breaks intuitively expected behaviour and possibly also some already existing code out there.
Just my 5 cent.
NathanaelA commentedon Feb 17, 2016
enchev commentedon Feb 18, 2016
Well, I was afraid of this. :) Possible option will be to restore the original behavior and provide additional optional parameter with
trueas default value:In this case you will be able to set this to
falseif you want to check only for files not for folders.Hey @atanasovg, @cokobware, what do you think?
lhitc commentedon Feb 18, 2016
If you want to implement both variants for convenience, it might be more consistent to have 3 different methods, like:
static exists(path: string): boolean; // classic behaviour
static isExistingRegularFile(path: string): boolean; // true if plain file
static isExistingFolder(path: string): boolean; // true if folder
atanasovg commentedon Feb 18, 2016
@lhitc .NET for one will NOT return true for a directory: https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx. But I guess our thinking is biased due to the fact that many of the core engineering team have extensive experience with .NET.
@enchev Given the default behavior on Node, iOS and Android is to return true for a simple
existscheck then any arbitrary parameters/methods added to the API seem artificial to me. If it is important for the user to check for a file explicitly he may do something likeSo, my vote goes for reverting the behavior to its previous state.
enchev commentedon Feb 18, 2016
I'm fine for reverting as well. Hey @cokobware what do you think?
lhitc commentedon Feb 18, 2016
@atanasovg Thanks for expanding my horizon. I admit I only checked with Java, PHP, Python, Ruby, Perl, classic C and a couple of web frameworks, which all seem to rely on the stat() system call.
So make that "a majority of programming languages and frameworks, especially in the context of web development" ;-)
cokobware commentedon Feb 18, 2016
I suppose reverting is fine. Having said that, like most of the NS team, my
experience is with .NET too and I find this result surprising given my
experience. I guess it feels very *nixy, which is fine if that is what I
was expecting. It makes sense to revert if that's how Node.js does it.
Perhaps a compromise would be to enhance the documentation to point out the
actual behaviour?
On Thu, Feb 18, 2016, 8:33 AM Vladimir Enchev notifications@github.com
wrote:
awebi commentedon Oct 12, 2018
So what is the solution to check if "isDirectory"?
lock commentedon Oct 12, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.