FileAttributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    FileAttributes

    This is the code:

    FileAttributes attributes = File.GetAttribu tes(sFileName);

    MessageBox.Show (attributes.ToS tring());



    The message box shows "ReadOnly, Archive"



    How do I test if the file is ReadOnly?

    I tried

    if (attributes == FileAttributes .ReadOnly)

    but it always give me false.


  • Jon Skeet [C# MVP]

    #2
    Re: FileAttributes

    Alan T wrote:
    This is the code:
    >
    FileAttributes attributes = File.GetAttribu tes(sFileName);
    >
    MessageBox.Show (attributes.ToS tring());
    >
    The message box shows "ReadOnly, Archive"
    >
    How do I test if the file is ReadOnly?
    >
    I tried
    >
    if (attributes == FileAttributes .ReadOnly)
    >
    but it always give me false.
    if ((attributes & FileAttributes. ReadOnly) != 0)
    {
    // Whatever
    }

    Jon

    Comment

    • Alan T

      #3
      Re: FileAttributes

      Is this ReadOnly or not ?
      if ((attributes & FileAttributes. ReadOnly) != 0)
      {
      // Whatever
      }

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: FileAttributes

        Alan T <alanpltseNOSPA M@yahoo.com.auw rote:
        Is this ReadOnly or not ?
        >
        if ((attributes & FileAttributes. ReadOnly) != 0)
        {
        // Whatever
        }
        The code in the body of the if statement will execute if it *is*
        ReadOnly.

        --
        Jon Skeet - <skeet@pobox.co m>
        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
        If replying to the group, please do not mail me too

        Comment

        Working...