formlesstree4 18 Report post Posted November 18, 2009 (edited) This program will use several string manipulation functions. I suggest you ask questions if you don't understand what I'm doing, but I will break down what I do for each step. (Video tutorial here on RapidShare since I've read people were having issues getting from Mediafire.) Opening up Visual Studio, we're going to place one ListBox, one Button, and one FolderBrowserDialog. If you don't know where these are, look on the video tutorial so you have a reference. Once placed, double click your button, and place the following code inside the Sub that Visual Studio was nice enough to create for us: If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then For Each f As String in IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath) Listbox1.Items.Add(f.Replace(String.Format("{0}\", SelectedFolderDialog.SelectedPath), String.Empty)) Next End If Now, let's break this code down so you can understand it (for those that chose not to get the video). 1: If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then This line is very simple, it will display a Folder Browsing Dialog for you to select your folder to load the files from. If you find your file and press OK (or double click the directory in some cases), then the If Statement will be true, and the code inside the If statement will be executed. 2: For Each f As String in IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath) This is the start of a loop. A loop will allow us to get all the files inside of the directory that we selected, hence the .SelectedPath at the end. 3: Listbox1.Items.Add(f.Replace(String.Format("{0}\", SelectedFolderDialog.SelectedPath), String.Empty)) This line is the biggest in the entire program. Basically, we were originally going to just add 'f', or the file including the path. I took it one step further invoking the .Replace() function of strings. Basically, we tell it what to replace and with what to replace it with. What the String.Format() returns is the entire FilePath, including the ending '\'. Then, after all of that, it adds the FileName to the ListBox in the order that they are found. 4: Next This is just a call that will continue the loop until all values have been read from the IO.Directory.GetFiles() list. Now, for your homework assignment. Using IO.Directory.GetFiles(), load all files into a listbox, and any text file, I want you to remove their extensions, as well as their leading paths. For example, let's say a file exists at: 'C:\foldername\text file.txt'. When you load it into the ListBox, it should be something like this: 'text file'. I shall have an example for you guys up later on tonight that will do just that. Edited November 18, 2009 by formlesstree4 Adding video tutorial Share this post Link to post Share on other sites
Kiriashi 117 Report post Posted November 18, 2009 Yay! Awesome! ^ _ ^ I'm loving these. Now if only I can get good at this. :3 Share this post Link to post Share on other sites