how to get directory value in C# code example
Example 1: c# windows application get current path
System.IO.Path.GetDirectoryName(Application.ExecutablePath);
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);
}
}
}
}