Results 1 to 4 of 4

Thread: Getting all file names from folder, editing them and putting them into a textbox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    18

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    18

    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

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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?
    Doctor Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width