Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear all,

I'm create windows application in C#, where i'm automating windows.

Currently i'm trying to achieve, Directory/folder attributes(Readonly/hidden/archive).

Below is my code which always return "DirAttributes = Directory" only, even though I set the folder properties to "Readonly/hidden" but it always return only "Directory".

What I have tried:

C#
public static bool EvaluateFolderProperties(string folder, WindowsFolderAttributes att)
        {
            bool result = false;
            if (Directory.Exists(folder))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(@"C:\NCIT");
                if (att == WindowsFolderAttributes.Hidden)
                    result = dirInfo.Attributes.HasFlag(FileAttributes.Hidden);
                else if (att == WindowsFolderAttributes.ReadOnly)
                    result = dirInfo.Attributes.HasFlag(FileAttributes.ReadOnly);
                else if (att == WindowsFolderAttributes.Archive)
                    result = dirInfo.Attributes.HasFlag(FileAttributes.Archive);
            }
            return result;
        }


Can anyone please help me.


Thanks in advance.
Posted
Updated 29-May-17 0:29am

1 solution

It might be that you are checking the same folder regardless of what you get passed:
DirectoryInfo dirInfo = new DirectoryInfo(@"C:\NCIT");
Perhaps using folder instead might be better?
Do note that ReadOnly only applies to files in a folder, not to the folder itself - you will always get False for that.
 
Share this answer
 
Comments
abdul subhan mohammed 29-May-17 7:01am    
can you help me, in code for folder.
OriginalGriff 29-May-17 7:10am    
You are joking, right?
DirectoryInfo dirInfo = new DirectoryInfo(folder);
Maciej Los 29-May-17 8:41am    
:laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900