My requirement is to read a file location retrieve the list of .jpg & .xml files along with their timestamp and write it to a file.
I am new to C#, so far i have been able to get the file list and write the output to a file, but i am not sure how to get the time stamp of file and write it along with list.
I have added code existing code, i would need to have a timestamp for every file in list so that I can use these details for a comparison downstream.
Please advise.
Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
class Program
{
static void Main()
{
TextWriter tw = new StreamWriter(@"C:\test\logfile_c#.txt");
// Put all xml file names in directory into array.
string[] array1 = Directory.GetFiles(@"C:\test","*.xml");
// Put all jpg files in directory into array.
string[] array2 = Directory.GetFiles(@"C:\test", "*.jpg");
// Display all XML files and write to text file.
Console.WriteLine("--- XML Files: ---");
foreach (string name in array1)
{
Console.WriteLine(name);
tw.WriteLine(name);
Console.ReadLine();
}
// Display all JPG files and write to text file..
Console.WriteLine("--- JPG Files: ---");
foreach (string name in array2)
{
Console.WriteLine(name);
tw.WriteLine(name);
Console.ReadLine();
}
tw.Close();
}
}
Output
C:\test\chq.xml C:\test\img_1.jpg C:\test\img_2.jpg