using System.IO; string sourceFile = @"C:\Users\Username\Documents\file.txt"; string destinationFile = @"C:\Users\Username\Downloads\file.txt"; File.Copy(sourceFile, destinationFile);
using System.IO; string sourceDirectory = @"C:\Users\Username\Documents\directory"; string destinationDirectory = @"C:\Users\Username\Downloads\directory"; Directory.CreateDirectory(destinationDirectory); foreach (string file in Directory.GetFiles(sourceDirectory)) { string fileName = Path.GetFileName(file); string destinationPath = Path.Combine(destinationDirectory, fileName); File.Copy(file, destinationPath); } foreach (string dir in Directory.GetDirectories(sourceDirectory)) { string dirName = Path.GetFileName(dir); string destinationPath = Path.Combine(destinationDirectory, dirName); Directory.CreateDirectory(destinationPath); CopyDirectory(dir, destinationPath); }In this example, we first create the directory at the destination path using `Directory.CreateDirectory(destinationDirectory)`. We then loop through all the files in the source directory using `Directory.GetFiles(sourceDirectory)` and copy each file to the destination directory using `File.Copy`. We also loop through all the subdirectories in the source directory using `Directory.GetDirectories(sourceDirectory)` and create a new subdirectory in the destination directory using `Directory.CreateDirectory(destinationPath)`. We then call the `CopyDirectory` method recursively to copy the subdirectory and all its contents to the destination directory. Package Library: System.IO.FileSystem The System.IO.FileSystem package provides the core file and directory manipulation functionality in C#, including the `File`, `Directory`, and `Path` classes. The `FileSystem` class provides additional methods for working with file and directory paths, such as `GetFileInfo` and `GetDirectoryInfo` for retrieving information about a file or directory, and `CreateDirectory` and `Delete` for creating and deleting directories.