I'm making a mini disk cleaner and I have wrote this code:

listView1.Items.Clear();

                DirectoryInfo dirCustom = new DirectoryInfo("C:\\Windows\\");

                FileInfo[] filCustom;

                filCustom = dirCustom.GetFiles("*.txt");

                foreach (FileInfo filFile in filCustom)
                {

                listView1.Items.Add(filFile.Name, "test");

                }

However there are some missing parts, works fine but i need to search multiple path and extensions and it only displays the file name on the list view on detailed view. I want it to display the folder path and file size.

MSDN example are always for console apps, because it is easy to give a small example.
Nothing prohibits you to use these examples in a Form app.
Line 12 of your code could become: listView1.Items.Add(filFile.FullName, "test");

someone on microsoft helped me i got this code:

listView1.Items.Clear();

                string[] directories = new string[] { "C:\\Windows\\", "c:\\" };
                string[] extensions = new string[] { "*.txt", "*.exe" };

                foreach (var dir in directories)
                {
                    var dirInfo = new DirectoryInfo(dir);
                    foreach (var ext in extensions)
                    {
                        foreach (var fileInfo in dirInfo.GetFiles(ext))
                        {
                            listView1.Items.Add(fileInfo.Name, "test");
                        }
                    }
                }

Only thing left is displaying the folder path and file size.

You can use the same methods in a Forms app. But instead of using WriteLine to show info to the user, you can show that info in a MessageBox, a Label, a List or a TextBox etc.

This article has been dead for over six months. Start a new discussion instead.