In a C# 20008 application, I would like to accomplish the following task:
1. I would like to find all the files named *summ.xls that exist in a general folder structure like: C:\temp. However all the files individually are at lower levels like
C:\temp\09_20_2012\CUSTOMER1.
I would like to be able search for the files giving only a partial path.
I know the following would work if I gave the full file path of
string[] files = Directory.GetFiles(C:\temp\09_20_2012\CUSTOMER1, "*summ.xls");
However I would like to know how to search for the "*summ.xls" by only giving the path C:\temp.
This way I would be able to look for all the applicable spreadhseets I need to work with.
2. Is there a way to be able to tell when the directory was last searched for a file? If so, how can I setup code to check for the "*summ.xls" file in the C:\temp directory from the last time the search was setup?
Loading

VulpesRank #55 · 29.2K reputationPosted Oct 8, 2012, 1:14 PM EDT
FroglegRank #1,020 · 1.9K reputationPosted Oct 8, 2012, 11:58 AM EDT
string[] files = Directory.GetFiles(C:\temp\09_20_2012\CUSTOMER1, "*summ.xls",SearchOption.AllDirectories);
VulpesRank #55 · 29.2K reputationPosted Oct 8, 2012, 12:03 PM EDT
string[] files = Directory.GetFiles("C:\\temp", "*summ.xls", SearchOption.AllDirectories);
If you're accessing files in the directory, you can obtain the date a particular file (or the directory itself) was last accessed by examining its LastAccessTime property.
However, if you just want to know when the directory was last searched for a file (by your program), then I'd create a Dictionary
For example:
// store dictionary at class level
private Dictionary
// in a method
dict.Add("c:\\temp\\*summ.xls", DateTime.Now);
// check if searched already
DateTime? lastSearchDate = null;
string filePath = "c:\\temp" + "\\" + "*.summ.xls";
if (dict.ContainsKey(filePath))
{
lastSearchDate = dict[filePath];
}
dcRank #2,247 · 627 reputationPosted Oct 8, 2012, 12:46 PM EDT
You did have this comment:
However, if you just want to know when the directory was last searched for a file (by your program), then I'd create a Dictionary
However my question is how am I going to save the value the last time the program searched the directroy path? Do I store the value in a file that the program has access to? Do I save the value as a hard-coded value in in the program somehow?
basically how doI have the dictionary datetime value?
dcRank #2,247 · 627 reputationPosted Oct 8, 2012, 7:28 PM EDT