Re: Check for multiple file attributes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 12/22/04


Date: Wed, 22 Dec 2004 14:56:53 -0500

Pete,

    || (and &&) are logical operators, meant to be used on boolean types. |
(and &) are bitwise operators, meant to be used on integral types for bit
masking.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"Pete Kane" <pk_fox@ntlworld.com> wrote in message 
news:bUjyd.1640$0k6.204@newsfe1-win.ntli.net...
> sorry Nicholas I posted directly to you, I thought I was on the right 
> lines but it's nice to have confirmation, BTW what's the difference 
> between | and || ?
>
> regards
>
> Pete Kane
>
> "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote 
> in message news:%23IJyuJF6EHA.2572@tk2msftngp13.phx.gbl...
>> Pete,
>>
>>    Yes, the FileAttributes enumeration is a bitwise mask, so you would 
>> compare in that manner.  However, you do have to make sure the result is 
>> not zero, because C# does not assume that a non zero integer value 
>> evaluates to true, rather, you have to use a boolean value.
>>
>>    In essence, you need to change your expression to this:
>>
>> if ((File.GetAttributes(fname) & (FileAttributes.ReadOnly | 
>> FileAttributes.Archive)) != 0)
>>
>>    Hope this helps.
>>
>>
>> -- 
>>               - Nicholas Paldino [.NET/C# MVP]
>>               - mvp@spam.guard.caspershouse.com
>>
>>
>> "Pete Kane" <pk_fox@ntlworld.com> wrote in message 
>> news:Fniyd.1525$0k6.840@newsfe1-win.ntli.net...
>>> Hello all, how can I check for multiple file attributes  using bitwise 
>>> operators ? I'm thinking along the lines of
>>>
>>>
>>> string fname = "c:\\test.txt";
>>> if(File.GetAttributes(fname) & (FileAttributes.ReadOnly | 
>>> FileAttributes.Archive ))
>>>
>>> {
>>>
>>> File.SetAttributes(fname,FileAttributes.Normal);
>>>
>>> }
>>>
>>> Basically I'm trying to say "If Readonly or Archive" then set the 
>>> attribute to normal, as you can tell I'm new to C#
>>>
>>>
>>>
>>
>>
>
> 


Relevant Pages

  • RE: Bitwise Comparison in WHERE Clause
    ... bitwise operators are provided by T-SQL. ... operators are used on int, smallint, or tinyint data. ...
    (microsoft.public.data.ado)
  • Re: program logic based on endianness
    ... The logic of shifting and action based on the result, ... assumes that the system is big-endian. ... I wanted to know if the above holds true for bitwise and and ... the bitwise operators -- work on the values of their ...
    (comp.unix.programmer)
  • Re: Bitwise OR and AND without bitwise operators....
    ... but how can I do the bitwise AND? ... Notice you can re-use some results if you work lsb to msb. ... So just iterate bitwise yourself and add 2^k to your result when the ...
    (sci.math)
  • Re: Check for multiple file attributes
    ... compare in that manner. ... because C# does not assume that a non zero integer value evaluates to ... how can I check for multiple file attributes using bitwise> operators? ...
    (microsoft.public.dotnet.languages.csharp)
  • Bitwise OR and AND without bitwise operators....
    ... I am working in a programming language which does not support ... but how can I do the bitwise AND? ...
    (sci.math)