matchoo Posted February 23, 2006 Posted February 23, 2006 Greetings, I know this is prob. is easy - but I am just starting out with C# and looking to do some experiments to learn faster. I would like a listbox to show all xml files in the current directory and all subdirectories. The xml file list should be sorted. When a user clicks on one of these files, it will open it in notepad. I'm sure this is easy to do - can you share how you would accomplish it? Thanks -mreider Quote
Leaders Iceplug Posted February 24, 2006 Leaders Posted February 24, 2006 Well, showing all the XML files in a directory is easy to do. Directory.GetFiles() will do most of the work for you. Finding the XML files in subdirectories is harder, because you first have to find the (sub)directories in the directory and then do the above to find all of the files in this directory. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Leaders snarfblam Posted February 25, 2006 Leaders Posted February 25, 2006 Finding the subdirectories should actually be pretty trivial if you are familiar with recursion (in terms of programming). As far as opening them in notepad, look into the System.Diagnostics.Process class. Quote [sIGPIC]e[/sIGPIC]
Karim Hyatt Posted February 25, 2006 Posted February 25, 2006 Greetings, I know this is prob. is easy - but I am just starting out with C# and looking to do some experiments to learn faster. Just in case you need extra information, here is a sample you can tweak. private void OnFormLoad(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { GetAllFiles(fbd.SelectedPath); } lbFiles.Sorted = true; } private void GetAllFiles(string startPath) { string[] files = Directory.GetFiles(startPath, "*.xml"); foreach (string s in files) lbFiles.Items.Add(s); string[] dirs = Directory.GetDirectories(startPath); foreach (string dir in dirs) GetAllFiles(dir); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.