Results 1 to 4 of 4

Thread: Renaming files in a folder with a format.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    2

    Renaming files in a folder with a format.

    Hello,

    I like to listen to audio books and frequently put them on my iPod when I purchase them on disc at a discounted price. Because they are on disc, and many are not already MP3 format, I have to "rip" them in order to make them MP3, compressing the size so I can add several to my iPod at a time. The program I use for ripping does not fill in the track names for each disc, but rather just lists "Track 1, 2 , 3 etc." At this point, I manually go into the folder, and rename the tracks to the name of the book, and then what track number it is example: "Gone 002". After I do this, it allows me to add it to my iPod and see exactly where I stop when needing to pause my book, or load it to play from the computer/phone if I don't have my iPod near me.

    My question is this: does anyone know of a coding script that I would be able to write, or have assistance with that would allow me to specify what the name of the book is, and then have the script/program itself go through the selected folder and change Track 01 to "Gone 01", Track 02 "Gone 02" etc. Also, because there are many discs, I know I'll have 25 tracks that will be named correctly, then need to add the 25 tracks that are on disc 2,3,4... etc. This program/script would need to be able to either see that there is already 25 tracks created with the proper name (knowing where it left off) or have the ability to select start at number "?" which can be user specified.

    I'm sure I'll need a loop to make this happen, and also have an integer that counts up so the program would know what the next number it needs to have would be. I also do not have any issues grabbing the user input for the title of what the beginning of the audio file should be called, followed by the integer that is set by the script/program. What I'm having troubles with is not knowing how to get the program to look at a specific folder in which I would need the renaming to be done.

    Thank you for any feedback, guidance/assistance that anyone can provide!!

    Nathan

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,679

    Re: Renaming files in a folder with a format.

    Here is a quick sub that I wrote that would rename files in a directory:
    Code:
    	Private Sub RewriteFiles(ByVal path As String, ByVal name As String)
    		'Get all files in the directory
    		Dim files() As IO.FileInfo = New IO.DirectoryInfo(path).GetFiles()
    
    		'Loop through each file
    		For x As Integer = 1 To files.Length
    			'Get the current file in the iteration
    			Dim currentFile As IO.FileInfo = files(x - 1)
    		
    			'Rename the file to the desired name, x, and the extension. IE:
    			'name = foo, x = 1, and extension = .mp3
    			'The new name would be foo1.mp3
    			My.Computer.FileSystem.RenameFile(currentFile, name & x.ToString & currentFile.Extension)
    		
    		Next
    	End Sub
    Although I get a little lost here:
    Also, because there are many discs, I know I'll have 25 tracks that will be named correctly, then need to add the 25 tracks that are on disc 2,3,4... etc. This program/script would need to be able to either see that there is already 25 tracks created with the proper name (knowing where it left off) or have the ability to select start at number "?" which can be user specified.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Renaming files in a folder with a format.

    First I would suggest using a program like Windows Media Player to rip music, because it will go out on the web using the SN of the CD and pull in all that info for you. In settings under "Rip Music" you can click the filename button where it gives you options on what you want to include in the MP3 file name when it is created, like track number, artist, album, etc..

    If you find it doesn't work for you, or you have lots of existing stuff you still need to rename, then here is some basic code to get you started:

    Code:
            Dim myDirectory As String = "C:\some folder\audiobooks\some audiobook" 'as example, but you should probably pull this from a textbox
            Dim myMP3Files = My.Computer.FileSystem.GetFiles(myDirectory, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
            Dim findText As String = "Track" 'THIS IS WHAT YOU WANT TO REPLACE WITH YOUR OWN TEXT
            Dim replaceText As String = "Gone" 'THIS IS YOUR OWN TEXT TO USE FOR REPLACEMENT 'as example, but you should probably pull this from a textbox
    
            'RENAME EACH MP3
            For Each myMP3File In myMP3Files
                My.Computer.FileSystem.RenameFile(myMP3File, IO.Path.GetFileName(myMP3File).Replace(findText, replaceText))
            Next

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    2

    Re: Renaming files in a folder with a format.

    Thank you both for your help and guidance with my inquiry. I've attempted to use the coding supplied above, and have still seemed to be unable to get the fire directory to work. I apologize for my confusion - it's been quite some time since I've done anything substantial for coding. Perhaps it would help me to show a photo of my form in hopes to better explain how I was trying to "link" my current structure to the coding that was provided to me.

    Attachment 125235

    I've created a text box named txtLocation for use for pointing one to the directory location of the folder in which the files for renaming are located.

    I've created a text box named txtBook for use of listing the portion of the text in which to be included for the title of the track. This was to be incorporated with an integer I had created called intFileNumber in which it would count up by "1" everytime a new track was named in order to create the name of "Gone 01".mp3.

    The previous tracks check box is after a first disc was named, and I would need to start with the intFileNumber starting as a value other than "0" That number would be indicated by using an If statement. If the check box was checked, the number entered in txtTrackNumber would equal intFileNumber (the next sequential number needed from the previous disc)
    example: 7 tracks on disc 1 and disc two has 10 tracks. chkTrack would be checked, so the value in txtTrackNumber would be 8.

    txtTotal would be how many tracks there were on the disc. And every time a new file would be named, the integer, intTrack would change by a value of "-1"

    The loop would stop when the value of intTrack was equal to "0".

    Last but not least of course, the button of Rename Files would initiate the whole procedure of renaming.

    What I'm still confused with at this point is how to get the program to proceed with naming the original tracks in the correct order, and also with getting the program to go about naming the tracks in the directory in which was specified by the user in the location text box.

    Again, sorry for any and all confusion on my behalf. I feel I'm on the right track, but I'm missing a few key things along the way. Any assistance in which can help me connect the missing "dots" would be greatly appreciated!!

    -Nathan

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