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
VulpesPosted Oct 8, 2012, 5:14 PM
dcPosted Oct 8, 2012, 11:28 PM
dcPosted Oct 8, 2012, 4:46 PM
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?
VulpesPosted Oct 8, 2012, 4:03 PM
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];
}
FroglegPosted Oct 8, 2012, 3:58 PM
string[] files = Directory.GetFiles(C:\temp\09_20_2012\CUSTOMER1, "*summ.xls",SearchOption.AllDirectories);