c# - How to get files from a directory created between two dates using DateTimePickers -
i want files created between 2 dates directory. dates selected 2 datetimepickers.
example (user selectable):
datetimerpicker1 = "15/09/2015"; datetimerpicker2 = "05/10/2015";
i put var
var datainicio = datainicial.value; var datafim = datafinal.value; string entradadediretorio = @"c:\\"; directoryinfo diretoriodeentrada = new directoryinfo(entradadediretorio); if (datainicio != datafim) { foreach (var arquivos in diretoriodeentrada.getfiles().where(f => f.creationtime >= datainicio && f.creationtime <= datafim)) { // call function } } else { foreach (var arquivos in diretoriodeentrada.getfiles().where(f => f.creationtime == datainicio && f.creationtime == datafim)) { // call function } }
if trying files directory within range of date try this:
var directory = new directoryinfo(your_dir); var files = directory.getfiles() .where(file => file.lastwritetime >= datetimepicker1 && file.lastwritetime <= datetimerpicker2);
edit 1: if both datepicker's value same can query either datepicker's date value , not query against range
if(datainicio != datafim) (var arquivos in diretoriodeentrada.getfiles().where(f => f.creationtime >= datainicio && f.creationtime <= datafim)); else (var arquivos in diretoriodeentrada.getfiles().where(f => f.creationtime == datainicio));
Comments
Post a Comment