pzozulka
asked on
C# code question
Is there anything wrong with the code below? Does the logic skip any files/folders in any conditions? In particular, the "Continue" statement is giving me doubt.
void Find(string folder)
{
/*
search this directory and all its subdirectories for files which
names/contents (chkMatchFileName/chkMatchFileContent) match the entered criteria
*/
bool matchFileName = chkMatchFileName.Checked;
bool matchFileContent = chkMatchFileContent.Checked;
// loop through files
string[] arrFiles = Directory.GetFiles(folder);
foreach (string file in arrFiles)
{
if (matchFileName)
{
// file name matches entered criteria
if (file.Contains(txtSearchText.Text))
{
AddToList(file);
continue; // to avoid dups, if item is added to ListBox, no need to add it again even if file content matches criteria.
}
}
if (matchFileContent)
{
// file content matches entered criteria
if (File.ReadAllText(file).Contains(txtSearchText.Text))
{
AddToList(file);
}
}
}
string[] arrDirs = Directory.GetDirectories(folder);
foreach (string dir in arrDirs)
{
Find(dir);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.