Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8096425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:26:48+00:00 2026-06-05T21:26:48+00:00

For some reason, when I try to check a file against FileAttributes.Normal, it seems

  • 0

For some reason, when I try to check a file against FileAttributes.Normal, it seems like almost none of my files are showing up in my search. According to the API, that’s because some other attributes are set. That’s OK, I’ll just need to search by what I don’t want. This is where the problem comes in.

I’m incredibly rusty on my bitwise operator math, especially when it comes to checking multiple things at once. I’m trying to figure out how to get an if statement to return false if any of a certain number of file attributes are present (i.e. NONE of the specified attributes can be found if it wants to pass through my search). Here’s what I’ve written so far:

if ((File.GetAttributes(stringFileName) &
   (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Archive |
    FileAttributes.Encrypted | FileAttributes.Temporary)) == 0)

I’m thinking that it should take the conglomerate of all the different attributes and compare them to the original attributes of the file. If any match is found, the entire thing is rendered zero. However, this doesn’t seem to be working as intended. Should I have used a different operator than the bitwise and (&)?

Thanks!

Update:

It appears that it wasn’t the bitmask logic that was the problem, but rather FileAttributes.Archive. For some reason my files were nearly all marked with this flag (perhaps indicating that they are destined for backup?). At least now I know, and knowing is half the battle. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:26:49+00:00Added an answer on June 5, 2026 at 9:26 pm

    If you want the files with only the Normal attribute set then

    if (File.GetAttributes(stringFileName) == FileAttributes.Normal)
        // True, file with only Normal attribute
    else
        // False, file with some attributes but not the Normal one
    

    According to MSDN FileAttributes.Normal means The file is normal and has no other attributes set. This attribute is valid only if used alone.

    After some research I think that the problem lies in the Archive attribute.
    Would you like to test with this simple code?

    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args.Length != 1)
                {
                    Console.WriteLine("Usage: CheckAllAtt <directoryName>");
                    return;
                }
                var files = Directory.GetFiles(args[0]);
                foreach (string fileName in files)
                {
                    FileAttributes att = File.GetAttributes(fileName);
                    DumpAttr(fileName, att);
                }
            }
            private static void DumpAttr(string fileName, FileAttributes att)
            {
                StringBuilder sb = new StringBuilder("File: " + fileName);
                if ((att & FileAttributes.Archive) == FileAttributes.Archive)
                    sb.Append(" Archive,");
                if ((att & FileAttributes.Compressed) == FileAttributes.Compressed)
                    sb.Append(" Compressed,");
                if ((att & FileAttributes.Device) == FileAttributes.Device)
                    sb.Append(" Device,");
                if ((att & FileAttributes.Directory) == FileAttributes.Directory)
                    sb.Append(" Directory,");
                if ((att & FileAttributes.Encrypted) == FileAttributes.Encrypted)
                    sb.Append(" Encrypted,");
                if ((att & FileAttributes.Hidden) == FileAttributes.Hidden)
                    sb.Append(" Hidden,");
                if ((att & FileAttributes.Normal) == FileAttributes.Normal)
                    sb.Append(" Normal,");
                if ((att & FileAttributes.NotContentIndexed) == FileAttributes.NotContentIndexed)
                    sb.Append(" Normal,");
                if ((att & FileAttributes.Offline) == FileAttributes.Offline)
                    sb.Append(" Offline,");
                if ((att & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    sb.Append(" ReadOnly,");
                if ((att & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
                    sb.Append(" ReparsePoint,");
                if ((att & FileAttributes.SparseFile) == FileAttributes.SparseFile)
                    sb.Append(" SparseFile,");
                if ((att & FileAttributes.System) == FileAttributes.System)
                    sb.Append(" System,");
                if ((att & FileAttributes.Temporary) == FileAttributes.Temporary)
                    sb.Append(" Temporary,");
    
                sb.Length -= 1;
                Console.WriteLine(sb.ToString());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
For some reason if I try to get the actual size of mystruct I
I'm getting undefined for some reason when I try to return the html via
This is my first applet project and for some reason when I try to
I'm hoping you can give me some pointers... For some reason when I try
For some reason every time I try to count the number of rows in
for some reason then i duplicate movie clip and try to put it in
For some reason, when I try to animate textColor , it won't work. The
I have the following code pasted below. For some reason, the response.redirect seems to
I have an AsynchFileUpload on my page and for some reason when I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.