The DirectoryInfo class exposes an "Attributes" property which is a
Flags enumeration on the FileAttributes enumeration. You should note
that a Directory is basically a file with a special attribute -
"Directory". Therefore, you should not clear that attribute, rather
you should always append to the existing enumerated value or remove
from it.
Here's a very simple Console app to demonstrate the concept.
---
class Program
{
static void Main(string[] args)
{
string input = args[0];
if(input == "hide")
{
ToggleHidden(true);
}
else if(input == "reveal")
{
ToggleHidden(false);
}
}
private static void ToggleHidden(bool hide)
{
DirectoryInfo d = new DirectoryInfo(@"C:\MySecretFolder");
if(d.Exists)
{
FileAttributes atts = d.Attributes;
if(hide == true)
{ // Hide the folder.
// Append Hidden attribute only if not already set.
if((atts & FileAttributes.Hidden) != FileAttributes.Hidden)
atts |= FileAttributes.Hidden;
}
else
{ // Show the folder.
// Remove Hidden attribute if set.
if((atts & FileAttributes.Hidden) == FileAttributes.Hidden)
atts &= ~FileAttributes.Hidden;
}
d.Attributes = atts;
}
}
}
---
In the same way you can set/unset other attributes such as ReadOnly/
Archive, etc.
On Jun 11, 6:48 pm, LostVB <[email protected]> wrote:
> I am usning VB Express 2008 and trying to change specific folder
> properties. I would like to set/unset - "show hidden files and
> folders" property. But I can't find any examples or even a direction
> to look/