.net - How to get names of files in a folder moved on a particular date in windows using C#? -
i coding using c# , .net on vs 2012.
there server cuts 2-3 files onto folder on computer everyday @ 3 am. need program gets filename , extension of file moved on current day. have tried numerous methods -
directoryinfo filepath = new directoryinfo("c:\\users\\gaurav\\desktop\\randomfolder"); fileinfo[] files = filepath.getfiles("*.txt"); foreach (fileinfo file in files) { if (file.lastwritetime > datetime.today) { filecount++; } }
however, file.lastwritetime gives date last written to. other methods file.creationtime gives date when created might not same date moved folder on computer. there way solve problem?
update: have no control on server cannot add timestamp when moved computer.
if have control on target machine create service watch directory , time stamp file @ point. here decent example of how create directory watch service: creating service monitor directory
then change event listener methods around liking, think changing file name or resetting creation time using system.io.file.setcreationtime(path, time);
option. like:
datetime time = new datetime(year, month, day, hour, minutes, seconds); if (file.exists(path)) file.setcreationtime(path, time);
Comments
Post a Comment