• Move files to folders based on MP3 tag

    Author
    Topic
    #460386

    I have a folder full of MP3s that I’d like to get into the proper folders easily.

    Currently they reside in G:MP3NewUnfiled

    I’d like them all to reside in this folder structure

    G:MP3Rock where is the Artist from the Artist tag in the MP3 file itself.

    Any pointers?

    Thanks!

    Viewing 1 reply thread
    Author
    Replies
    • #1164082

      I have a folder full of MP3s that I’d like to get into the proper folders easily.

      Er, sort of, although my software skills are currently under a cloud

      I have had dropped on me 20GB of music files. My job is to tidy up the folder tree.
      I am attaching a work-in-progress UserGuide.

      So far I have reduced file space by 33% just by eliminating duplicate tracks (*) within each folder.
      I eliminated more by eliminating duplicate tracks within the folder tree.
      I am now enhancing a better technique, which includes a GUI form to allow the user to sample tracks (“PLAY”) prior to deletion.
      I have plans to assemble the contents of separate folders into a single folder so that a folder “Genius Loves Company” which appears frequently throughout the tree with only one track per instance (always Ray Charles, but this time with Willie Nelson, next time with John Lennon, Chris Greaves etc.) can be assembled into a single “Ray Charles” folder.
      I have macros to delete any non-accredited files (WMA, MP3, WAV etc)

      Since the application uses ShellExecute to “play” a track, it ought to be just as good at cleaning up a folder tree of images (BMP, JPG etc), or a folder tree of documents (DOC, RTF, WPD etc.)

      (*) I strip the name of the extent and of all non-alphabetic characters – the cheap man’s Soundex search – to reach a status of “probably a duplicate”

    • #1164147

      Here’s code you can use. You can copy it into a module in any Office application and run it from there.

      Make a backup before trying it, to be on the safe side!

      Code:
      Sub MoveMP3()
        Const intRecordLen = 128
        ' The following constants should end in a backslash!
        Const strSourcePath = "G:MP3NewUnfiled"
        Const strDestRoot = "G:MP3Rock"
      
        Dim strDestPath As String
        Dim strFile As String
        Dim lngFileLen As Long
        Dim tag As MP3Tag
        Dim strArtist As String
        Dim f As Integer
        Dim intP As Integer
        Dim arr() As String
        Dim n As Integer
      
        ' Loop through MP3 files in source folder
        strFile = Dir(strSourcePath & "*.mp3")
        Do While Not strFile = ""
      	lngFileLen = FileLen(strSourcePath & strFile)
      	f = FreeFile
      	Open strSourcePath & strFile For Binary Access Read As #f
      	' Read MP3 tag
      	Get #f, lngFileLen - intRecordLen + 1, tag
      	Close #f
      	If tag.ID = "TAG" Then
      	  ' If it's a valid MP3, get artist name
      	  strArtist = Trim(tag.Artist)
      	  intP = InStr(strArtist, Chr(0))
      	  If intP > 0 Then
      		strArtist = Left(strArtist, intP - 1)
      	  End If
      	  strDestPath = strDestRoot & strArtist & ""
      	  ' Store info in array
      	  n = n + 1
      	  ReDim Preserve arr(1 To 2, 1 To n)
      	  arr(1, n) = strDestPath
      	  arr(2, n) = strFile
      	End If
      	strFile = Dir
        Loop
      
        ' Loop through array
        For n = 1 To UBound(arr, 2)
      	strDestPath = arr(1, n)
      	strFile = arr(2, n)
      	If Dir(strDestPath, vbDirectory) = "" Then
      	  ' Create folder if it doesn't exist yet
      	  MkDir strDestPath
      	End If
      	' Move file
      	Name strSourcePath & strFile As strDestPath & strFile
        Next n
      End Sub
    Viewing 1 reply thread
    Reply To: Move files to folders based on MP3 tag

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: