Skip to content

Fix up NativeItemExists() in Utils.cs #171

Closed

Description

TODO PSL replace by System.IO.File.GetAttributes VSO create date - 9/1/2015 14:59:00

Activity

  1. changed the title [-]monad Utils.cs: fix up NativeItemExists()[/-] [+]Fix up NativeItemExists() in Utils.cs[/+] on Feb 26, 2016
  2. palladia commented on Mar 24, 2016

    @palladia
    Contributor

    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:

    1. Put try/catch around File.GetAttributes(), as this call will throw if path does not exist.
    2. 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().

  3. andyleejordan commented on Apr 2, 2016

    @andyleejordan
    MemberAuthor

    George Fleming (@palladia) Was this resolved or do more decisions need to be made?

  4. palladia commented on Apr 4, 2016

    @palladia
    Contributor

    Closing this item since current implementation is good enough. See explanation above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions