dir folder c# code example
Example 1: get folders in directory c#
string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);
Example 2: c# directory
using System;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string sourceDirectory = @"C:\current";
string archiveDirectory = @"C:\archive";
try
{
var txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt");
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourceDirectory.Length + 1);
Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName));
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}