How is the directory used in C#?

In C#, the Directory class offers methods and properties for manipulating directories. You can use the Directory class to create, move, delete, copy directories, and retrieve information about directories.

Some common methods of the Directory class include:

  1. Create a new directory with the specified path using Directory.CreateDirectory().
  2. Delete a directory using the specified path.
  3. Move a directory from one location to another using the Directory.Move method.
  4. Check if a directory exists.
  5. GetDirectories method in Directory class is used to retrieve the subdirectories of a specified directory.
  6. Retrieve the files in the specified directory using Directory.GetFiles(string path).

Original sentence: 我想起了小时候我和朋友一起玩耍的快乐时光。

Paraphrased sentence: I recalled the happy times when I played with friends in my childhood.

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string path = @"C:\MyFolder";

        // 创建一个新目录
        Directory.CreateDirectory(path);

        // 在新目录中创建一个新文件
        File.Create(Path.Combine(path, "myfile.txt"));

        // 获取新目录中的所有文件
        string[] files = Directory.GetFiles(path);
        foreach (string file in files)
        {
            Console.WriteLine(file);
        }

        // 删除新目录
        Directory.Delete(path, true);
    }
}
Leave a Reply 0

Your email address will not be published. Required fields are marked *