Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order files list by batch

I have a long list of individual songs not in folders just songs, and I'd like to move them to the folder of theire artist. the songs are in the following format

artist - songname.flac

I can store them in a list, and echo it, but splitting the artist and songname in 2 vars, I can't seem to figure out.

Could someone help me with the splitting (or if you want even with the rest of the script)

this is what I have so far:

@echo off
setlocal enabledelayedexpansion
set N=0
for %%i in (*) do (
    set Files[!N!]=%%~ni
    set /a N+=1

)
for /l %%x in (1,1,%N%) do echo.!Files[%%x]!

pause
like image 872
Kiwi Avatar asked Nov 21 '25 10:11

Kiwi


2 Answers

set SOURCE=c:\temp\test
for /f "delims=-. tokens=1,2" %%i in ('dir /b "%SOURCE%\*.flac"') do echo Artist : %%i  Song : %%j

update for full script (got to check if it works with space and special chars in path) :

@echo off
setlocal enabledelayedexpansion
set SOURCE=c:\temp\test
set DESTINATION=c:\temp\test

for /f "tokens=*" %%i in ('dir /b "%SOURCE%\*.flac"') do call :OrderThatMess "%%i"

:OrderThatMess

set NAME=%1
for /f "tokens=1,2 delims=-. " %%j in (%1) do (
    set ARTIST=%%j
    set TITLE=%%k
    if not exist "%DESTINATION%\%ARTIST%" (md "%DESTINATION%\%ARTIST%" )
    copy %SOURCE%\%NAME% "%DESTINATION%\%ARTIST%\%TITLE%.flac"
    )
like image 77
Loïc MICHEL Avatar answered Nov 23 '25 02:11

Loïc MICHEL


@echo OFF &SETLOCAL ENABLEDELAYEDEXPANSION
for %%i in (*.flac) do (
    set /a N+=1
    FOR /f "tokens=1,2 delims=- " %%o IN ("%%~ni") DO (
        set "FilesA[!N!]=%%~o"
        set "FilesB[!N!]=%%~p"
    )
)
for /l %%x in (1,1,%N%) do echo(!FilesA[%%x]! !filesB[%%x]!
like image 39
Endoro Avatar answered Nov 23 '25 02:11

Endoro