M
M
maxcad2021-07-17 23:06:28
C++ / C#
maxcad, 2021-07-17 23:06:28

How do I know if a flag is included in the sum of flags?

The situation is this. I was looking for how to find out if a folder is a symlink. I found this
https://docs.microsoft.com/ru-ru/dotnet/api/system...

FileAttributes attributes = File.GetAttributes("c:/Temp/testfile.txt");

This code returns the sum of the flags. For symlinks in this sum, one of the terms = 1024.
For a normal folder symlink, 1040 is returned, which is 1024+16. What does it mean in Russian - a directory and a symlink.
Since the folder may have many more attributes, the number may not always be 1040.

My task is to find out from a decimal number whether it has a flag equal to 1024.
How can I implement this in C#?
Or if anyone knows how to check a folder / file for a symlink in other ways bypassing bitwise mathematics.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kokapuk, 2021-07-17
@maxcad

FileInfo pathInfo = new FileInfo(path);
bool pathInfo.Attributes.HasFlag(flag);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question