Change your if statement to:
if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
You need to use the bitmask since Attributes is a flag enum. It can have multiple values, so hidden folders may be hidden AND another flag. The above syntax will check for this correctly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…