473,770 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for multiple file attributes

Hello all, how can I check for multiple file attributes using bitwise
operators ? I'm thinking along the lines of
string fname = "c:\\test.t xt";
if(File.GetAttr ibutes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive ))

{

File.SetAttribu tes(fname,FileA ttributes.Norma l);

}

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#

Nov 16 '05 #1
4 12289
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.GetAttri butes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive)) != 0)

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:Fn******** ********@newsfe 1-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.t xt";
if(File.GetAttr ibutes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive ))

{

File.SetAttribu tes(fname,FileA ttributes.Norma l);

}

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#

Nov 16 '05 #2
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]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@tk2msf tngp13.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.GetAttri butes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive)) != 0)

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:Fn******** ********@newsfe 1-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.t xt";
if(File.GetAttr ibutes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive ))

{

File.SetAttribu tes(fname,FileA ttributes.Norma l);

}

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#


Nov 16 '05 #3
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]
- mv*@spam.guard. caspershouse.co m

"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:bU******** ********@newsfe 1-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]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@tk2msf tngp13.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.GetAttri butes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive)) != 0)

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:Fn******** ********@newsfe 1-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.t xt";
if(File.GetAttr ibutes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive ))

{

File.SetAttribu tes(fname,FileA ttributes.Norma l);

}

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#



Nov 16 '05 #4
thanks Nicholas, have a good Xmas...

regards

Pete Kane
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:eE******** *****@TK2MSFTNG P14.phx.gbl...
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]
- mv*@spam.guard. caspershouse.co m

"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:bU******** ********@newsfe 1-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]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@tk2msf tngp13.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.GetAttri butes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive)) != 0)

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Pete Kane" <pk****@ntlworl d.com> wrote in message
news:Fn******** ********@newsfe 1-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.t xt";
if(File.GetAttr ibutes(fname) & (FileAttributes .ReadOnly |
FileAttributes. Archive ))

{

File.SetAttribu tes(fname,FileA ttributes.Norma l);

}

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#




Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2573
by: Philipp H. Mohr | last post by:
Hello, I would like to store multiple dictionaries in a file, if possible one per line. My code currently produces a new dictionary every iteration and passes it on to another peace of code. In order to be able to re-run some experiments at a later date I would like to store every dictionary in the same file. I looked at pickel, but that seems to require a whole file for each dictionary.
2
6036
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x < 20; x++) { document.all('mySpan'+x).style.display = "inline"; } But I don´t know how many SPAN elements there are, so I need to set x to a
1
5879
by: DraguVaso | last post by:
Hi, I found some examples for storing the FormSettings of a Form in an XML-file, but none of these could match my criteria: What I am looking for is the possibility to save the FormSettings of multiple Instances of 1 form. I have a Form frmSource from which I have multiple Instances, each with a unique Identifier. So when I Load or Close a specific instance, I want to load or save the Settings (Top, Height, Width, etc) in an XML-file....
2
11695
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? I was looking to use the XML serialization to be able to translate complex XML elements in a single XML file through XML serialization as opposed to using SAX and coding my own serializer. However, the XML Serialization API appears to only...
6
2408
by: Shashi | last post by:
I have developed ASP.Net application using .Net 1.1 Framework. When the user clicks image file through Java script I am using my search window as below. QueryString = "frmMySearchWebForm.aspx?DOBDate=" + txtDOBDt popUp =window.open(QueryString,null, "height=50,width=80,status=no,left =0,top =0,toolbar=no,menubar=no,location=no,scrollbars =yes"); When the user picks a certain customer in the frmMySearchWebForm I am
8
1829
by: Ken Capriell | last post by:
I know that subject probably did not adequately explain anything so here goes... I have an access file that needs to be transposed from its current format to a new format so that I can then export as a flat file to be imported into a shopping cart. This file is to create a set of attributes/options for each product. The file I have is in a pretty standard format:
6
3502
by: Homer J. Simpson | last post by:
Hi all, I have enough experience with HTML/classic ASP to get by, and I'm trying to learn ASP.NET. Traditionally, I've taken the habit of breaking out extra-long CSS files into multiple, smaller ones, and referring to them in my HTML/ASP files on an as-needed basis. Essentially, I've organized things as: /default.asp
0
3245
by: malsh1358 | last post by:
Hi I need check required elements and attributes in JAXB java classes , if there are any value for them place it , otherwise place default value in xml file , because of it I upgrade JAXB2.0 to JAXB 2.1 to support "required" in "XmlElement" , I read in "JavaWS(JAXB)Tutorial.pdf" that JAXB itself check required elements and attributes , if there are any value for them place it , otherwise place default value in xml file , the exact part of...
15
1393
by: null | last post by:
I am using the NotifyFilters enumeration type. In 'integer' the values are ored together, and I can use AND to check for equality like so If bNotifyFilter And NotifyFilters.Attributes Then However, when option strict is on this does not work, any ideas?
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.