Getting all file names from folder, editing them and putting them into a textbox
Hi, I am a bit lazy. I have a folder with over a 1000 mp3s in and I want to list all of their names. I have created this
Code:
Private Sub Command1_Click()
Dim filter As String
filter = "MP3 Files Only (*.MP3)|*.MP3|"
CommonDialog1.FilterIndex = 1
CommonDialog1.filter = filter
CommonDialog1.Action = 1
Text1.Text = (CommonDialog1.FileTitle)
Dim OldFileName As String
Dim NewFileName As String
sOldFileName = Text1.Text
sNewFileName = Replace(Text1.Text, "[www.technoapell.com].mp3", "")
Text2.Text = Text2.Text + vbCrLf + Text1.Text
Text3.Text = Text3.Text + 1
End Sub
This copys a selected mp3's name into text2 and also counts which mp3 it was (I want to know the exact number of songs). But there is a problem. I want my songs in text2 to be with out "[www.technoapell.com].mp3", but the upper code doesn't work:(
Could some1 tell me what's wrong or just edit the code to work.
Also, is there a way that I can choose all the songs at once and not one at a time like in this case ?
Thanks for the help:blush:
Re: Getting all file names from folder, editing them and putting them into a textbox
Try something like this. Add the code for your commondialog in if you want. Note, I'm using a Listbox not a TextBox. For something like this, a ListBox makes more sense.
Code:
Dim strLoad As String
List1.Clear
strLoad = Dir("d:\*.mp3")
Do While strLoad > vbNullString
sOldFileName = strLoad
sNewFileName = Replace(sOldFileName, "[www.technoapell.com].mp3", "")
List1.AddItem sNewFileName
strLoad = Dir
Loop
Re: Getting all file names from folder, editing them and putting them into a textbox
Sorry, I think you understood me wrong. Your code does the same as mine (except the name changing, but I fixed that now). I now just want to know if there is a way to copy all the filenames from a folder to a listbox, with out writing a path to every .mp3 file in the code
Re: Getting all file names from folder, editing them and putting them into a textbox
If you want to ignore the path and show only the file name in the list box, then use InStRev( ), which will point to the last back slash in the path. The file name is then everything in the path to the right of where the last backslash is found by InStrRev( ). Is that what you want?