is very straightforward: it does exactly what its name suggests. In fact,
it will create any directories in the whole path that do not already
exist, so you can create a deep hierarchy with a single call. (You’ll
notice that Example 11-14 didn’t bother to
create the Programming
CSharp\FindDuplicates folder—those will get created
automatically the first time we run as a result of creating the temporary
folders inside them.) A side effect of this is that it is safe to call it
if all of the directories in the path already exist—it will just do
In addition to the overload we’ve used, there’s a second
which also takes a
Directory.CreateDirectory(string path, DirectorySecurity directorySecurity)
allows you to specify filesystem access controls with a relatively simple
programming model. If you’ve tried using the Win32 ACL APIs, you’ll know
that it is a nightmare of GUIDs, SSIDs, and lists sensitive to item
ordering. This model does away with much of the complexity.
Let’s extend our create function to make sure that only our current user has read/write/modify permissions on these directories. Example 11-15 modifies the previous example by explicitly granting the current user full control of the newly created folders. The new or changed lines are highlighted.
Example 11-15. Configuring access control on new directories
private static string MakeTestDirectories() ...