Directory
In this page:
Directory
The Directory class provides static methods for creating, checking, listing, and deleting folders, such as Directory.CreateDirectory and Directory.Exists. Directory.GetFiles returns the files inside a folder as an array of paths. It's the folder-level counterpart to the file-level File class.
Note: Directory.CreateDirectory does nothing (and doesn't throw) if the directory already exists.
Example: Directory
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string folder = "reports";
Directory.CreateDirectory(folder);
Console.WriteLine(Directory.Exists(folder));
File.WriteAllText(Path.Combine(folder, "a.txt"), "data");
string[] files = Directory.GetFiles(folder);
foreach (string f in files)
{
Console.WriteLine(f);
}
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: