DirectoryInfo class provides some basic features to create,
copy, move, rename and delete operations. It also provides some basic
information like directory name, full path, attribute, root name etc. Let’s
have a look on below code which loop through all the files and directories in
specific directory.

DirectoryInfo di
= newDirectoryInfo(@"d:\temp");

Console.WriteLine(di.FullName);

//gets
all files in temp directory

foreach (FileInfo file in
di.GetFiles())

Console.WriteLine(file.Name);

//gets
all directories in temp directory

foreach (DirectoryInfo dir in
di.GetDirectories())

Console.WriteLine(dir.Name);

How to get Special Folders?

Special folders are defined under Environment.SpecialFolder
enum. This enum is available in System.Environment class. Let’s see how to get
path for special folders like MyDocuments, MyPictures, Desktop, ProgramFiles,
System, Windows etc.