// Example 1: Add a directory to another directory DirectoryInfo sourceDirectory = new DirectoryInfo(@"C:\Users\JohnDoe\Documents\SourceDirectory"); DirectoryInfo targetDirectory = new DirectoryInfo(@"C:\Users\JohnDoe\Documents\TargetDirectory"); targetDirectory.CreateSubdirectory(sourceDirectory.Name); Directory.Move(sourceDirectory.FullName, Path.Combine(targetDirectory.FullName, sourceDirectory.Name));
// Example 2: Get all subdirectories of a directory DirectoryInfo directory = new DirectoryInfo(@"C:\Users\JohnDoe\Documents"); foreach (var subDirectory in directory.GetDirectories()) { // Do something with the subdirectory }This example uses the GetDirectories method to get all the subdirectories of the directory and then iterates through them using a foreach loop. The package library used in these examples is part of the .NET Framework, specifically the System.IO namespace.