Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.IO.Directory: practical reference

System.IO.Directory: practical reference: Directory creates, enumerates, moves, and deletes file-system directories.

Version: .NET API; verified on .NET 10.0.14

Syntax

System.IO.Directory /* select a documented member or constructor */

Directory creates, enumerates, moves, and deletes file-system directories.

Use it with complete handling for permissions, races, and platform-specific path behavior.

Checking before an operation does not remove TOCTOU races, and symbolic links can change the actual target.

CreateDirectory is idempotent for an existing directory, but a collision with a file throws.

The complete program actually uses System.IO.Directory; its exact expected stdout is True.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var directory = Path.Combine(Path.GetTempPath(), $"cktis-kb-directory-{Guid.NewGuid():N}");
try
{
    Directory.CreateDirectory(directory);
    Console.WriteLine(Directory.Exists(directory));
}
finally
{
    if (Directory.Exists(directory))
        Directory.Delete(directory, recursive: true);
}

Result

True

The complete program actually uses `System.IO.Directory`; its exact expected stdout is `True`.

Sources