List m3u files in folder and choose it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

List m3u files in folder and choose it

#1 Post by kpropell » 11 Oct 2009 17:12

Hi!
I'm wondering if its a easier way of doing this. Been searching the forum for hints (and taking code;) the script work, but there will be alot of hardcoding I guess.. And there must be a better way of doing what I want.

I have this folder with m3u files. And I want a script to list them up in a cmd window for me to choose (From 1 to x). Then this consol player (mpxplay) will play that m3u file :)

Right now i have this:



@echo off
color 30
title Playlist chooser
echo.
echo ----- Choose your playlist -----
echo.
:START
set list="C:\Documents and Settings\Administrator\Desktop\Playlist"
set player=C:\Programs\MPXPLAY\MPXPLAY.EXE
Echo.1. Tool - Aenima
Echo.2. Tool - Salival
Echo.3. Tori Amos - Abnormally Attracted To Sin
Echo.4. Harrys Gym - Harrys Gym
Echo.5. The Flaming Lips - Yoshimi Battles the Pink Robots
Echo.6. A Perfect Circle - Thirteenth Step
Echo.7. A Perfect Circle - Mer De Noms
Echo.8. The National Bank - The National Bank
Echo.9. Radiohead - Kid A
ECHO.
ECHO.0. Exit
ECHO.
(SET OPTION=)
(SET /P OPTION="> ")
IF NOT DEFINED OPTION (GOTO:START)
FOR /L %%A IN (0,1,9) DO (
IF ^%OPTION:~0,1%==^%%A (GOTO:_%%A)
)
GOTO:START
:_0
EXIT
:_1
START %player% %list%\Aenima.m3u
GOTO:START
:_2
START %player% %list%\Salival.m3u
GOTO:START
:_3
START %player% %list%\AbnormallyAttractedToSin.m3u
GOTO:START
:_4
START %player% %list%\HarrysGym.m3u
GOTO:START
:_5
START %player% %list%\YoshimiBattlesthePinkRobots.m3u
GOTO:START
:_6
START %player% %list%\ThirteenthStep.m3u
GOTO:START
:_7
START %player% %list%\merdenoms.m3u
GOTO:START
:_8
START %player% %list%\thenationalbank.m3u
GOTO:START
:_9
START %player% %list%\kida.m3u
GOTO:START


If I add, say 30 more playlist I will have to hardcode ALOT since I don't know anyother way... Helpi ? :)

Kjell Øyvind

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 12 Oct 2009 10:43

Code: Select all

@echo off
setlocal enabledelayedexpansion
set cnt=1

set "list=c:\tmp"
:start
cls
for /f "delims=*" %%a in ('dir /b /a-d "%list%"') do (
   echo !cnt! - %%a
   set "file!cnt!=%%a"
   set /a cnt+=1
)
echo.
echo 0 - Exit
set /p option="> "
if "%option%"=="0" exit
for /l %%a in (1,1,%cnt%) do if "%option%"=="%%a" call :process "%%a"
set cnt=1
goto :start
:process
echo start "%player%" "%list%\!file%~1!"
set cnt=1
pause
goto :start

kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

#3 Post by kpropell » 12 Oct 2009 11:13

Thanks! Needed to do some editing. But one thing does not work..
Number 1 will not play.. All the others will, but not 1...

@echo off
setlocal enabledelayedexpansion
set cnt=1
set "player=C:\Programs\MPXPLAY\MPXPLAY.EXE"
set "list=C:\Documents and Settings\Administrator\Desktop\Playlist"
:start
cls
for /f "delims=*" %%a in ('dir /b /a-d "%list%"') do (
echo !cnt! - %%a
set "file!cnt!=%%a"
set /a cnt+=1
)
echo.
echo 0 - Exit
set /p option="> "
if "%option%"=="0" exit
for /l %%a in (1,1,%cnt%) do if "%option%"=="%%a" call :process "%%a"
set cnt=1
goto :start
:process
start %player% "%list%\!file%~1!"
set cnt=1
pause
goto :start


If you look at the picture, the 1 different from the others.. Testet changing the name so that another one would be number 1, but it's still the same case.. 1 is not working :) !
Image

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 12 Oct 2009 11:57

You have a space after the "1" on one of the set lines:

set cnt=1

It's a problem with cut/paste on this website.

kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

#5 Post by kpropell » 12 Oct 2009 12:13

Brilliant! And many thanks! Ever tried mpxplay btw? Gotta love the retro look 8)

Image

Post Reply