I need to use C# to search a directory (C:\Logs) for log files whose name starts with ACCESS. Once I find a file that begins with ACCESS I need to search that file and make a collection of strings that start with Identity=” ” An example would be Identity=”SWN\smithj” so I need everything from Identity to the last double quotes collected. After I have reached the end of the file, I need to go to the next file that begins with ACCESS. Can someone show me how to do this in C#?
Many thanks
It looks like you’ve got two functions here:
1) Find the Files with names like ACCESS*
2) Search those files for lines like “Identity=*”
To do the first, use a DirectoryInfo object and the GetFiles() method with a search pattern of “ACCESS*”.
Then you’ll loop through those files looking for the data you need.
This hasn’t been compiled, so double check it, but it should be pretty close to what you need.
EDIT: Added full solution based on comments from OP. Has been compiled and run.