My C# code detects changes in files and folders attributes, using the two following snippets:
// For files
return (IO.File.GetAttributes(Source) != IO.File.GetAttributes(Dest))
// For folders
IO.DirectoryInfo SourceInfo = new IO.DirectoryInfo(AbsSource);
IO.DirectoryInfo DestInfo = new IO.DirectoryInfo(AbsDest);
return (SourceInfo.Attributes != DestInfo.Attributes);
I noticed that IO.File.GetAttributes
seems to work folder folders just as well, and so I was wondering whether I could drop the directory-specific part and just use the one-liner for both files and folders.
Is that possible ? Is reading IO.DirectoryInfo.Attributes
equivalent to calling File.GetAttributes
?
Thanks!
Yes, same thing. You can tell from the class inheritance. The FileInfo and DirectoryInfo classes both inherit the non-abstract Attribute property from the abstract FileSystemInfo class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With