D
Daniel Garavaldi
Hi C# Gurus
Has anybody of you experience with FileAttributes?
I'm looking for alternatives and elegant solutions when opening a file
with FileInfo and query the file-attributes (read-only, archive ...)
What I do at the moment is mapping the fileInfo.Attributes to my
enum-type
private enum AttributeTypes {ReadOnly = 0, Normal = 1, Archived = 2,
Directory = 3};
By opening the file I get all the attributes into a string ....
FileInfo f = FileInfo("c:\hello.txt");
string attr = f.Attributes.ToString();
... and can of course parse it.
static void SetFileAttribueFlags(string attribute)
{
string attr = attribute.ToUpper();
//readonly
if(attr.IndexOf(FileAttributes.ReadOnly.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.ReadOnly] = true;
//normal
if(attr.IndexOf(FileAttributes.Normal.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Normal] = true;
//archive
if(attr.IndexOf(FileAttributes.Archive.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Archived] = true;
//directory
if(attr.IndexOf(FileAttributes.Directory.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Directory] = true;
}
Any idea to do it with .NET-Attributes (f.e. [FlagsAttribute()] )
Looking forward reading something from you.
By the way: attached the complete code. The console program expects an
input parameter that means a full qualified filename.
Has anybody of you experience with FileAttributes?
I'm looking for alternatives and elegant solutions when opening a file
with FileInfo and query the file-attributes (read-only, archive ...)
What I do at the moment is mapping the fileInfo.Attributes to my
enum-type
private enum AttributeTypes {ReadOnly = 0, Normal = 1, Archived = 2,
Directory = 3};
By opening the file I get all the attributes into a string ....
FileInfo f = FileInfo("c:\hello.txt");
string attr = f.Attributes.ToString();
... and can of course parse it.
static void SetFileAttribueFlags(string attribute)
{
string attr = attribute.ToUpper();
//readonly
if(attr.IndexOf(FileAttributes.ReadOnly.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.ReadOnly] = true;
//normal
if(attr.IndexOf(FileAttributes.Normal.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Normal] = true;
//archive
if(attr.IndexOf(FileAttributes.Archive.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Archived] = true;
//directory
if(attr.IndexOf(FileAttributes.Directory.ToString().ToUpper()) >= 0)
fileAttributes[(int)AttributeTypes.Directory] = true;
}
Any idea to do it with .NET-Attributes (f.e. [FlagsAttribute()] )
Looking forward reading something from you.
By the way: attached the complete code. The console program expects an
input parameter that means a full qualified filename.