Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
1.3 kB
1
Indexable
Never
@echo off
setlocal enabledelayedexpansion

REM Prompt the user for the source directory
set /p sourceDir="Enter the path to the directory containing the songs: "

REM Prompt the user for the target directory
set /p targetDir="Enter the path to the target directory where folders will be created: "

REM Prompt the user for the base name of the generated folders
set /p baseName="Enter the base name for the folders: "

REM Prompt the user for the number of songs per folder
set /p songsPerFolder="Enter the number of songs per folder: "

REM Create a list of all songs
cd "%sourceDir%"
set count=0
for %%f in (*.mp3) do (
    set /a count+=1
    set "file[!count!]=%%f"
)

REM Shuffle the list of songs
for /L %%i in (%count% -1 1) do (
    set /a "j=%%i*%random%/(32768+1)+1"
    set "temp=!file[%%i]!"
    set "file[%%i]=!file[%j%]!"
    set "file[%j%]=!temp!"
)

REM Create folders and move files
set folderIndex=1
set fileCount=0

for /L %%i in (1,1,%count%) do (
    if !fileCount! GEQ %songsPerFolder% (
        set /a folderIndex+=1
        set fileCount=0
    )
    set /a fileCount+=1
    if not exist "%targetDir%\%baseName%_!folderIndex!" mkdir "%targetDir%\%baseName%_!folderIndex!"
    move "%sourceDir%\!file[%%i]!" "%targetDir%\%baseName%_!folderIndex!\"
)

echo All songs have been organized.
pause
Leave a Comment