The DirectoryInfo class offers a reasonable set of methods for creating, deleting, moving, and so on. For instance, we could create a new directory at some arbitrary location. (In the following example, the new directory is created within the current directory.) We could then create a subdirectory within the new directory, set and then get some attributes, and finally delete both the subdirectory and the newly created parent directory: dir = new DirectoryInfo("Foo"); if (false == dir.Exists) dir.Create();DirectoryInfo dis = dir.CreateSubdirectory("Bar"); dis.Attributes |= FileAttributes.Hidden | FileAttributes.Archive;Console.WriteLine("{0,-10}{1,-10}{2}", dis.Name, dis.Parent, dis.Attributes);dis.Delete(true); dir.Delete(true);The output follows: Bar Foo Hidden, Directory, Archive
if (false == dir.Exists)
dir.Create();DirectoryInfo dis = dir.CreateSubdirectory("Bar");
dis.Attributes |= FileAttributes.Hidden | FileAttributes.Archive;Console.WriteLine("{0,-10}{1,-10}{2}",
dis.Name, dis.Parent, dis.Attributes);dis.Delete(true);
dir.Delete(true);The output follows: Bar Foo Hidden, Directory, Archive
(DirectoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden