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
Currently, we call File.Exists() and Directory.Exists() to see if path is directory or file, AND if path exists.
Yes, we could do something like:
FileAttributes fa = new File.GetAttributes(path);
if (fa & FileAttributes.Directory == FileAttributes.Directory)
{
// is directory
}
else
{
// is not directory
}
But above code doesn't answer the question of whether the file/directory exists. To do so, we would need to either:
Put try/catch around File.GetAttributes(), as this call will throw if path does not exist.
Do something like:
FileInfo fi = new File.FileInfo(path);
if (fi.Exists)
{
// it's a file
}
DirectoryInfo di = new Directory.DirectoryInfo(path);
if (di.Exists)
{
// it's a directory
}
else
{
// it doesn't exist
}
I'm not sure if either solution is better or faster than current implementation of using File.Exists() and Directory.Exists().
Activity
[-]monad Utils.cs: fix up NativeItemExists()[/-][+]Fix up NativeItemExists() in Utils.cs[/+]palladia commentedon Mar 24, 2016
Currently, we call File.Exists() and Directory.Exists() to see if path is directory or file, AND if path exists.
Yes, we could do something like:
FileAttributes fa = new File.GetAttributes(path);
if (fa & FileAttributes.Directory == FileAttributes.Directory)
{
// is directory
}
else
{
// is not directory
}
But above code doesn't answer the question of whether the file/directory exists. To do so, we would need to either:
FileInfo fi = new File.FileInfo(path);
if (fi.Exists)
{
// it's a file
}
DirectoryInfo di = new Directory.DirectoryInfo(path);
if (di.Exists)
{
// it's a directory
}
else
{
// it doesn't exist
}
I'm not sure if either solution is better or faster than current implementation of using File.Exists() and Directory.Exists().
andyleejordan commentedon Apr 2, 2016
George Fleming (@palladia) Was this resolved or do more decisions need to be made?
palladia commentedon Apr 4, 2016
Closing this item since current implementation is good enough. See explanation above.