I’m want to build an application in VC++ 2008 (Windows form application).
Here I want to browse a folder of my choice (push button “browse”), such that when I press the “scan” button my application will find all the files in the folder I chose, including subfolders. Then all files are placed in a listbox, I have this code will be in c# not in c++, how to change my code in c++?
private void btnScan_Click_1(object sender, EventArgs e)
{
List<string> search = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories).ToList();
progressBar1.Maximum = search.Count;
//foreach (Directory.GetDirectories.search))
foreach(string item in search)
{
try
{
StreamReader stream = new StreamReader(item);
string read = stream.ReadToEnd();
foreach(string st in viruslist)
{
if(Regex.IsMatch(read,st))
{
viruses+=1;
label1.Text+= viruses;
listBox1.Items.Add(item);
}
progressBar1.Increment(1);
}
}
catch(Exception ex)
{
}
}
}
Since your have a .NET application ( since you are using Windows Forms) the easiest way is to use System::IO::Directory::GetFiles() list all of the files in a folder and all subfolders.
The AllDirectories option causes GetFiles to search for files in all sub folders.