-1

I recently have been cleaning up my messy music files, but was doing a lot of moving searching and dragging when I remembered I could potentially have a batch file help me. I have made a file for every artist, but the artist is located in the "author" section, not the file name, picture attached as


Image


My question is, can I make a batch file that can have it look at the "Author" part of the files, find the name I am looking for, and if the name of the artist is there, move that file or files into the folder of that artist. I only know for the last part I will use something to this degree

move Source-Folder-Path Destination-Folder-Path

and the

If (condition) (do_something) ELSE (do_something_else) 

but I don't really know what to do from there...

Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 1
    No. Batch files have no native capability to read the meta information of the file. You need to either find a 3rd party utility to help the batch file or pick a different programming language. – Squashman Jan 30 '22 at 00:43

1 Answers1

1

With pure batch we can't get Meta Information of mp3 file; but you can try using vbscript with a batch file :

So, this an attempt to test :

  • you should change this variable : Set "Folder=%userprofile%\Downloads\Music\"

to your Music Folder path


@echo off
Title Get Author from mp3 file and move it to Author Folder
Color 0B
Set "Folder=%userprofile%\Downloads\Music\"
Set "Ext=mp3"
CD /D "%Folder%"
@for /R "%Folder%" %%F in (*.%Ext%) do (
    Set "File=%%~nxF"
    Setlocal EnableDelayedExpansion
    Call :GetAuthor "!File!" Author
    If Defined Author (echo( "!File!" ==^> Author = !Author!)
    If "!Author!" NEQ "" (
            MkDir "!Author!" 2>nul
            Move "!File!" "!Author!" 2>nul
    )
    EndLocal
)
pause & Exit
::-----------------------------------------------------------------------
:GetAuthor <File> <Author>
Set "VBSFile=%Temp%\%~n0.vbs" 
(
    echo MediaFile = "%~1"
    echo Const Authors = 20
    echo Dim oShell  : Set oShell  = CreateObject("Shell.Application"^)
    echo Dim oFolder : Set oFolder = oShell.Namespace("%Folder%"^)
    echo Dim oFile   : Set oFile   = oFolder.ParseName(MediaFile^)
    echo Dim Author : Author = oFolder.GetDetailsOf(oFile,Authors^)
    echo Dim fso    : Set fso = CreateObject("Scripting.FileSystemObject"^)
    echo If fso.FileExists("%Folder%"^& MediaFile ^&""^) Then wscript.stdout.Write Author
)>"%VBSFile%"
For /f "delims=" %%a in ('Cscript //nologo "%VBSFile%"') do Set "%2=%%a"
Exit /b
::-----------------------------------------------------------------------
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • I apologize, I am not familiar with VBscripting...is this the excel coding? And if so do I need to test this code in a notepad or in excel VB? Also, if possible could you explain this code a little more? – nitemare13 Jan 31 '22 at 01:33
  • @nitemare13 NO ! This is a batch file, so you just save it as `Music_by_Author.bat` ***NB:*** The extension must be `.bat` – Hackoo Jan 31 '22 at 07:26
  • So everywhere you have green text above needs to be replaced, right? And where there are "!" or "%" need to stay? – nitemare13 Jan 31 '22 at 18:02
  • Did you know the whole path of your folder ? Just replace ***%userprofile%\Downloads\Music\*** by your real path to your music folder – Hackoo Jan 31 '22 at 18:29