c#: Hello i need help. How can i use the returned list \"allDates\" as a portion
ID: 3919937 • Letter: C
Question
c#: Hello i need help. How can i use the returned list "allDates" as a portion of my directory.GetFiles(***********) . The dates are in the names of the files so i wanted use the the datetimepickers to get all the dates between. i have files in this format 20180522_test.csv.
First would i convert allDates to string and then just stick allDates in getfiles , like this .GetFiles(selectedpath,allDates+".csv",searchOption.AllDirectories);
Syntax:
private void button2_Click(object sender, EventArgs e)
{
string earliestdate = dateTimePicker1.Value.ToString("yyyyMMdd");
string latestdate = dateTimePicker2.Value.ToString("yyyyMMdd");
DateTime earliestDate = DateTime.ParseExact(earliestdate, "yyyyMMdd", CultureInfo.InvariantCulture);
DateTime latestDate = DateTime.ParseExact(latestdate, "yyyyMMdd", CultureInfo.InvariantCulture);
List<DateTime> DatesBetween( earliestDate, DateTime latestDate)
{
List<DateTime> allDates = new List<DateTime>();
for (DateTime date = earliestdate; date <= latestdate; date = date.AddDays(1))
allDates.Add(date);
return allDates.ToString();
}
list<string> fileDirectories = new List<string>();
if (checkedListBox1.GetItemCheckState(0) == CheckState.Checked)
{
if (checkedListBox2.GetItemCheckState(0) == CheckState.Checked)
{
fileDirectories.Add(@"C: opsource_oMeasurementAttu");
}
else if
{ // nothing}
else if {//nothing}
foreach (string selectedPath in fileDirectories)
{
string[] level1 = Directory.GetFiles(selectedPath, ".csv" , SearchOption.AllDirectories);
foreach (string level2 in level1)
{
Construct.pathList.Add(level2);
}
}
}
Explanation / Answer
.GetFiles(selectedpath,allDates+".csv",searchOption.AllDirectories);
In the GetFiles method you have to call the method that returns the allDates list namely DatesBetween with the required parameters.
For example:
.GetFiles(selectedpath,DatesBetween(earlist date, last date)+".csv",searchOption.AllDirectories);
so, that will return you a list of dates in string as you mentioned, then it will append with the "csv".
If the above solution is helpful to you in any way please rate it Or if you have any concerns please comment it, I will help you through
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.