Please see below code for your query. You can use this code in console application and use it.
static void Main(string[] args)
{
GetFileNamesandWriteInTxt();
}
public static void GetFileNamesandWriteInTxt()
{
string path = @'X:\myfolder\photos';
DirectoryInfo dr = new DirectoryInfo(path);
FileInfo[] mFile = dr.GetFiles();
StreamWriter writer = new StreamWriter("D:\\FileNames.txt", true);
foreach (FileInfo fiTemp in mFile)
{
writer.WriteLine(fiTemp.Name);
Console.WriteLine(fiTemp.Name);
}
Console.ReadLine();
}
Hope this will work for you!
Thanks, Anshul