getfiles - Get File timstamp and pipe with output of filelist in C# -
my requirement read file location retrieve list of .jpg & .xml files along timestamp , write file.
i new c#, far have been able file list , write output file, not sure how time stamp of file , write along list.
i have added code existing code, need have timestamp every file in list can use these details 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 xml file names in directory array. string[] array1 = directory.getfiles(@"c:\test","*.xml"); // put jpg files in directory array. string[] array2 = directory.getfiles(@"c:\test", "*.jpg"); // display xml files , write text file. console.writeline("--- xml files: ---"); foreach (string name in array1) { console.writeline(name); tw.writeline(name); console.readline(); } // display jpg files , write 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
depends timestamp you're after. can creation time using:
new fileinfo(filename).creationtime; that'll give datetime. can do:
tw.writeline(new fileinfo(name).creationtime.tostring()); the .tostring() optional - can use control date/time format used in output. there's modified time property can use if want instead.
Comments
Post a Comment