Solved Library of files in batchfile

August 5, 2011 at 14:19:53
Specs: Windows 7, Intel Celeron Duo T3300 @ 2GHz 64MB L2
Hello everyone on the forum,

How do I make a list of files (library) of *.mid files, spread over my harddisk in a batch file?
I've googled as good as possible but didn't really find something.

More specifically, imagine a 200GB HD, with ~400 MIDI's here and there. I want them to fit in a screen like below, is there also a way to add something like "Refresh"? :

===== (begin spoiler) =====
:playscr0
cls
echo.
echo Loading library...
echo Searching for files...
cd %temp%
if exist AltSynn del /q AltSynn
@mkdir AltSynn
cd AltSynn
@mkdir watched
cd watched
dir %userprofile%\documents *.mid /b /s>list.txt
for /f "delims=" %%a in ('findstr /r /n "^" list.txt') do set var=%%a
for /f "delims=" %%a in ('findstr /c:test list.txt') do set var=%%a
start head.bat 1 list.txt

:playsonglib
cls
echo.
echo AltSynn \ Songlibrary (Choose song)
echo.
echo [Q] %songvar01%
echo [W] %songvar02%
echo [E] %songvar03%
echo [R] %songvar04%
echo [T] %songvar05%
echo [Y] %songvar06%
echo [U] %songvar07%
echo [I] %songvar08%
echo [O] %songvar09%
echo [P] %songvar10%
echo [A] %songvar11%
echo [S] %songvar12%
echo.
echo [Z] Scroll Down...
echo.
echo [R]
echo [X] Configure
echo [C] Return to Mainmenu
echo.
choice /c:qwertyuiopaszxcr
if errorlevel 16 goto refreshlib
if errorlevel 15 goto main
if errorlevel 14 goto configscr00
REM ------- etc. etc.
===== (end spoiler) =====
note: head.bat is located at http://stackoverflow.com/questions/...

Thanks,
-- randomray


See More: Library of files in batchfile

Report •


✔ Best Answer
August 10, 2011 at 23:23:32
Ok, I think I understand....

@echo off
SetLocal EnableDelayedExpansion

Set tempdir="%temp%\%~n0_Listdir\%random%"
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a


if exist "%~dp0\filesearch.txt" (
    for /f "usebackq delims=" %%a in ("%~dp0\filesearch.txt") do (
        set filesearch==%%a
    )
)


:playscr0
color 70
mode 85,35

2>nul del /q %tempdir%
2>nul md %tempdir%
pushd %tempdir%

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set listfiles=0
set linecnt=0
set selfile=1


for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
set /a linecnt=^(linecnt %% 12^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo Watching: %filesearch%
echo [Z] Previous, [X] Refresh, [C] Next, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n
set selection=%errorlevel%
if %errorlevel% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file="%%b"
)
if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz1
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q %tempdir%
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0


:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz0
)
if errorlevel 2 goto main
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)
> "%~dp0\filesearch.txt" echo %filesearch%



echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

:configscrz1
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz1
)
if errorlevel 2 goto playscr0
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)
> "%~dp0\filesearch.txt" echo %filesearch%


echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

...

:quit
exit



#1
August 5, 2011 at 14:22:40
Edit: sorry forgot to mention the batchfile I posted (above) isn't/may not be entirely correct

Report •

#2
August 5, 2011 at 23:01:13
Maybe something like this:

@echo off
SetLocal EnableDelayedExpansion

cd /d %temp%
2>nul del /q "%~n0_listdir"
2>nul md "%~n0_listdir"
cd "%~n0_listdir"

:refresh
cls
echo Loading data, please wait....


set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S" "#13=D") do set %%~a
for %%a in ("#14=F" "#15=G" "#16=H" "#17=J" "#18=K" "#19=L") do set %%~a
 
for /f "tokens=*" %%a in ('dir /s /b c:\*.exe') do (
    set /a linecnt=^(linecnt %% 19^) + 1
    if !linecnt!==1 (
        set /a listfiles+=1
        type nul > list!listfiles!.txt
    )
    for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)



:loop
cls
echo -=Previous, +=Next, *=refresh, qwertyuiopasdfghjkl=select, x=Exit

Echo Page %selfile% of %listfiles%
type list%selfile%.txt
choice /c:QWERTYUIOPASDFGHJKL-+*X /n 
set selection=%errorlevel%
if %selection% lss 20 (
    for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
       set file=%%b
    )
    if "!file!"=="*" (goto loop) else goto done
)
if %selection%==20 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %selection%==21 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %selection%==22 goto refresh
if %selection%==23 exit /b
goto loop

:done
echo !file! was selected
pause


Report •

#3
August 6, 2011 at 02:26:35
Thanks, Judago.

Actually, this is just a part of a very bigger piece of batch file, that's why I haven't displayed everythin'.

But could you please modify it a little bit so it refreshes only everytime I open this piece, and that I can choose which folders this batchfile watches? Because it starts looking in $RECYCLE BIN$ first then I have to wait a few minutes to have it searched my whole 200 GB harddisk.

Also, it doesn't fit on the screen, the maximum of characters in a DOS window vertically is 23 or so... And at the end it says: "Error: Wrong choice. You may only chooze from A-Z, a-z and 0-9" or something like that...

I have modified a little, but could you help me doing the mentioned above?:

=====
:playscr0
cd /d %temp%
2>nul del /q "%~n0_listdir"
2>nul md "%~n0_listdir"
cd "%~n0_listdir"

:refrscr0
cls
echo.
echo.
echo Loading songlibrary, standby...

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S" "#13=D") do set %%~a
for %%a in ("#14=F" "#15=G" "#16=H" "#17=J" "#18=K" "#19=L") do set %%~a

for /f "tokens=*" %%a in ('dir /s /b c:\*.mid') do (
set /a linecnt=^(linecnt %% 19^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:loop
cls
echo -=Previous, +=Next, *=refresh, qwertyuiopasdfghjkl=select, x=Exit

Echo Page %selfile% of %listfiles%
type list%selfile%.txt
choice /c:QWERTYUIOPASDFGHJKL-+*X /n
set selection=%errorlevel%
if %selection% lss 20 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto loop) else goto done
)
if %selection%==20 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %selection%==21 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %selection%==22 goto refresh
if %selection%==23 exit /b
goto loop


:done
echo !file! was selected
pause
=====

===== =====
:playscr0
cd /d %temp%
2>nul del /q "%~n0_listdir"
2>nul md "%~n0_listdir"
cd "%~n0_listdir"

:refrscr0
cls
echo.
echo.
echo Loading songlibrary, standby...

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S" "#13=D") do set %%~a
for %%a in ("#14=F" "#15=G" "#16=H" "#17=J" "#18=K" "#19=L") do set %%~a

for /f "tokens=*" %%a in ('dir /s /b c:\*.mid') do (
set /a linecnt=^(linecnt %% 19^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:loop
cls
echo -=Previous, +=Next, *=refresh, qwertyuiopasdfghjkl=select, x=Exit

Echo Page %selfile% of %listfiles%
type list%selfile%.txt
choice /c:QWERTYUIOPASDFGHJKL-+*X /n
set selection=%errorlevel%
if %selection% lss 20 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto loop) else goto done
)
if %selection%==20 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %selection%==21 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %selection%==22 goto refresh
if %selection%==23 exit /b
goto loop


:done
echo !file! was selected
pause


Report •

Related Solutions

#4
August 6, 2011 at 03:53:32
You are going to have to figure some things out for yourself,
but I will help out a little. After all this is about what you
want to do with your script.

But could you please modify it a little bit so it refreshes
only everytime I open this piece,

I don't know what you mean... Perhaps you have to work on the
over all flow control of your script. The script I posted generates
a series of text file and displays them, the "refresh" option
regenerates the files(to display added/no display removed files).

I can choose which folders this batchfile watches

I have added in a variable where you can add a list of search
patterns. I'm not sure what exactly your after.


the maximum of characters in a DOS window vertically is 23 or so
I brought it back down to 12 options, but you should know
about the mode command. it can change the buffer size.
The window may also change size, but mode decides that itself:

mode 150,30

And at the end it says: "Error: Wrong choice. You may
only chooze from A-Z, a-z and 0-9" or something like that...

That's my fault, I'm not running Win7 and didn't realize that they
had crippled the choice command. Choice has been around
for a while(20+ years?) and the older versions accept almost all printable
characters(I was using -+*).....


@echo off
SetLocal EnableDelayedExpansion
rem the above ^ two commands can just go at the
rem top of the whole script, no need to repeat



:playscr0
rem delimited list of dir search strings
rem subfolders are also searched
set filesearch="c:\windows\system32\*.exe";"d:\home\*.exe";"c:\Documents and Settings\*.exe"


2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
echo Loading data, please wait....

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
    set /a linecnt=^(linecnt %% 12^) + 1
    if !linecnt!==1 (
        set /a listfiles+=1
        type nul > list!listfiles!.txt
    )
    for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)



:selscr0
cls
echo 4=Previous, 6=Next, 8=refresh, qwertyuiopas=select, x=Exit

Echo Page %selfile% of %listfiles%
type list%selfile%.txt
choice /c:QWERTYUIOPAS468X /n 
set selection=%errorlevel%
if %selection% lss 13 (
    for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
       set file=%%b
    )
    if "!file!"=="*" (goto selscr0) else goto filescr0
)
if %selection%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %selection%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %selection%==15 goto refrscr0
if %selection%==16 exit /b
goto selscr0

:filescr0
popd
rd /s /q "%temp%\%~n0_listdir"
echo !file! was selected
pause


Report •

#5
August 6, 2011 at 10:18:41
Judago,

I've been messing around with the script you wrote here it is:


===== =====
:playscr0
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
set /a linecnt=^(linecnt %% 12^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXM /n
set selection=%errorlevel%
if %selection% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto main
goto selscr0

:filescr0
popd
rd /s /q "%temp%\%~n0_listdir"
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto refrscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0

:errscr05
cls
echo.
echo.
echo AltSynn \ Error 05
echo.
echo AltSynn was unable to open the file with Synthesia.
echo Synthesia may be not installed, or AltSynn is uncompatible
echo with your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr06
cls
echo.
echo.
echo AltSynn \ Error 06
echo.
echo AltSynn was unable to open the file with MuseScore.
echo MuseScore may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr07
cls
echo.
echo.
echo AltSynn \ Error 07
echo.
echo AltSynn was unable to open the file with Anvil Studio.
echo Anvil Studio may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr08
cls
echo.
echo.
echo AltSynn \ Error 08
echo.
echo AltSynn was unable to open the file with Windows Media Player.
echo Windows Media Player may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:quit
exit

===== =====


(AltSynn is how I call it)
If I want to start !file! with some programs (like "program.exe !file!", where !file! is an argument) , !file! must be packed in in quotes f.e. ==> "C:\Cool Music.mid" because it contains spaces. No matter how I try to fix this, the program keeps giving me an "usage-error".

Also, after :sendfilewmp I wanted to add the configuration. To do so I have to change selscr0 like:


===== =====
:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n
set selection=%errorlevel%
if %selection% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz0
if %errorlevel%==17 goto main
goto selscr0

===== =====


and add somewhere


===== =====
:configscrz0
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
choice /c:mr /n
if errorlevel 2 goto refscr0
if errorlevel 1 (
set /p %filesearch%="Type the paths of the folders to be watched in quotes and separated by a semicolon. Use [Enter] to apply or [Ctrl]+[C] to cancel: "
)
echo [Any] Return to library
pause>nul
goto selscr0

===== =====
Am I doing it right?
Thanks for help,
-- randomray


Report •

#6
August 6, 2011 at 14:07:12
It's me again,

I've done the best I could, where should I place the "if filesearch2 is given replace filesearch with filesearch2" line? Look, it's almost finished:

===== =====
:playscr0
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
set /a linecnt=^(linecnt %% 12^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n
set selection=%errorlevel%
if %selection% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz0
if %errorlevel%==17 goto main
goto selscr0

:filescr0
popd
rd /s /q "%temp%\%~n0_listdir"
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto refrscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd %systemdrive%
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0


:configscrz0
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
set filesearch2=
choice /c:mr /n
if errorlevel 2 goto refrscr0
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by a semicolon.
set /p %filesearch2%="Use [Enter] to apply, leave empty to cancel: "
)
echo.
echo New value set.
echo [Any] Return to library
pause>nul
goto playscr0

:errscr05
cls
echo.
echo.
echo AltSynn \ Error 05
echo.
echo AltSynn was unable to open the file with Synthesia.
echo Synthesia may be not installed, or AltSynn is uncompatible
echo with your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr06
cls
echo.
echo.
echo AltSynn \ Error 06
echo.
echo AltSynn was unable to open the file with MuseScore.
echo MuseScore may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr07
cls
echo.
echo.
echo AltSynn \ Error 07
echo.
echo AltSynn was unable to open the file with Anvil Studio.
echo Anvil Studio may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr08
cls
echo.
echo.
echo AltSynn \ Error 08
echo.
echo AltSynn was unable to open the file with Windows Media Player.
echo Windows Media Player may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:quit
exit
===== =====
Could you please help me, after this my script is finally finished.
thanks
-- randomray


Report •

#7
August 6, 2011 at 15:14:11
First off you can just add the double quotes around the variable when needed or even add them to the variable at the start:

........
if %selection% lss 13 (
    for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
        set file="%%b"
    )
    if !file!=="*" (goto selscr0) else goto filescr0
)
......

The important thing is that you only double quote once.


Other than that it seems ok to me.


Report •

#8
August 6, 2011 at 15:19:29
I just saw this:

set /p %filesearch2%="Use [Enter] to apply, leave empty to cancel: "

The %'s of !'s mean that the command will try to set to the contents of the variable, not the variable itself.

set /p filesearch2="Use [Enter] to apply, leave empty to cancel: "


Report •

#9
August 6, 2011 at 17:43:09
I just spotted another issue:

cd %systemdrive%

You may want to change that to:

cd /d %systemdrive%\

In case the script is run from another drive.


Report •

#10
August 7, 2011 at 02:48:12
I've changed it but still this isn't very clear for me,
- where and how should I replace filesearch with the user-given filesearch2?

I discovered something you did wrong all the time; take a look at a piece of the script you wrote:
===== =====
Echo Page %selfile% of %listfiles%
type list%selfile%.txt
choice /c:QWERTYUIOPASDFGHJKL-+*X /n
set selection=%errorlevel%
if %selection% lss 20 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file=%%b
)
if "!file!"=="*" (goto loop) else goto done
)
if %selection%==20 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %selection%==21 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %selection%==22 goto refresh
if %selection%==23 exit /b
goto loop
===== =====
The only way to make this work was that I had to replace %selection% with %errorlevel%, which actually doesn't make much sense because you should normally be able to maximally add 1 to 9 %x things, right?


Report •

#11
August 7, 2011 at 05:09:20
The only way to make this work was that I had to replace %selection% with %errorlevel%

I set the errorlevel to selection to avoid it being changed:

set selection=%errorlevel%

- where and how should I replace filesearch with the user-given filesearch2?

That was something you added an I just ran with it. You could always just:

set filesearch=!filesearch2!

... or even just do away with filesearch2 in favour of !filesearch!. Basically you can get rid of it after you decide the new variable is a suitable replacement.


Report •

#12
August 7, 2011 at 08:04:23
Hi Judago, thanks again.

I tried what you said, but I really can't make this get to work:

===== =====

:playscr0
color 70
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

if !filesearch2! gtr [] set filesearch=!filesearch2!

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
	set /a linecnt=^(linecnt %% 12^) + 1
	if !linecnt!==1 (
		set /a listfiles+=1
		type nul > list!listfiles!.txt
	)
	for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n 
set selection=%errorlevel%
if %errorlevel% lss 13 (
	for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
		set file="%%b"
	)
	if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz0
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q "%temp%\%~n0_listdir"
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto playscr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto playscr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto playscr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto playscr0




:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
set filesearch2=
choice /c:mr /n
if errorlevel 2 goto playscr0
if errorlevel 1 (
	echo.
	echo Type the paths of the folders to be watched in quotes and separated by a semicolon. 
	set /p filesearch2="Use [Enter] to apply, leave empty to cancel: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main





:errscr05
cls
echo.
echo.
echo AltSynn \ Error 05
echo.
echo AltSynn was unable to open the file with Synthesia.
echo Synthesia may be not installed, or AltSynn is uncompatible
echo with your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr06
cls
echo.
echo.
echo AltSynn \ Error 06
echo.
echo AltSynn was unable to open the file with MuseScore.
echo MuseScore may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr07
cls
echo.
echo.
echo AltSynn \ Error 07
echo.
echo AltSynn was unable to open the file with Anvil Studio.
echo Anvil Studio may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr08
cls
echo.
echo.
echo AltSynn \ Error 08
echo.
echo AltSynn was unable to open the file with Windows Media Player.
echo Windows Media Player may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main




:quit
exit

===== =====

What am I doing wrong?
thanks,

-- randomray


Report •

#13
August 8, 2011 at 06:16:27
Modified some more, but question remains: how do I replace filesearch if given?

===== =====

:playscr0
color 70
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set emptystr=
if %filesearch2% gtr %emptystr% set %filesearch%=%filesearch2%

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
	set /a linecnt=^(linecnt %% 12^) + 1
	if !linecnt!==1 (
		set /a listfiles+=1
		type nul > list!listfiles!.txt
	)
	for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

set /a cfgvar=2
choice /c:QWERTYUIOPASZCXBM /n 
set selection=%errorlevel%
if %errorlevel% lss 13 (
	for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
		set file="%%b"
	)
	if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz1
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q "%temp%\%~n0_listdir"
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0




:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
set filesearch2=
choice /c:mr /n
if errorlevel 2 goto main
if errorlevel 1 (
	echo.
	echo Type the paths of the folders to be watched in quotes and separated by a semicolon. 
	set /p filesearch="Use [Enter] to apply, leave empty to cancel: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

:configscrz1
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
set filesearch2=
choice /c:mr /n
if errorlevel 2 goto playscr0
if errorlevel 1 (
	echo.
	echo Type the paths of the folders to be watched in quotes and separated by a semicolon. 
	set /p filesearch="Use [Enter] to apply, leave empty to cancel: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto playscr0



:errscr05
cls
echo.
echo.
echo AltSynn \ Error 05
echo.
echo AltSynn was unable to open the file with Synthesia.
echo Synthesia may be not installed, or AltSynn is uncompatible
echo with your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr06
cls
echo.
echo.
echo AltSynn \ Error 06
echo.
echo AltSynn was unable to open the file with MuseScore.
echo MuseScore may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr07
cls
echo.
echo.
echo AltSynn \ Error 07
echo.
echo AltSynn was unable to open the file with Anvil Studio.
echo Anvil Studio may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr08
cls
echo.
echo.
echo AltSynn \ Error 08
echo.
echo AltSynn was unable to open the file with Windows Media Player.
echo Windows Media Player may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main




:quit
exit

===== =====

Report •

#14
August 8, 2011 at 12:49:42
Filesearch kept being reset when looping back, it's just a default so just set it one at the top of the script.

@echo off
SetLocal EnableDelayedExpansion
rem this is a default, just set it at the top
rem of the script, otherwise it will be constyantly be reset
rem when looping
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"


===== =====

:playscr0
color 70
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched


2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set emptystr=

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
	set /a linecnt=^(linecnt %% 12^) + 1
	if !linecnt!==1 (
		set /a listfiles+=1
		type nul > list!listfiles!.txt
	)
	for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo.
echo [Z] Previous, [C] Next, [X] Refresh, [B] Configure, [M] Exit to mainmenu

set /a cfgvar=2
choice /c:QWERTYUIOPASZCXBM /n 
set selection=%errorlevel%
if %errorlevel% lss 13 (
	for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
		set file="%%b"
	)
	if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz1
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q "%temp%\%~n0_listdir"
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0




:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
choice /c:mr /n
if errorlevel 2 goto main
if errorlevel 1 (
	echo.
	echo Type the paths of the folders to be watched in quotes and separated by a semicolon. 
	set /p filesearch="Use [Enter] to apply, leave empty to cancel: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

:configscrz1
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [M]odify
echo [R]eturn
choice /c:mr /n
if errorlevel 2 goto playscr0
if errorlevel 1 (
	echo.
	echo Type the paths of the folders to be watched in quotes and separated by a semicolon. 
	set /p filesearch="Use [Enter] to apply, leave empty to cancel: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto playscr0



:errscr05
cls
echo.
echo.
echo AltSynn \ Error 05
echo.
echo AltSynn was unable to open the file with Synthesia.
echo Synthesia may be not installed, or AltSynn is uncompatible
echo with your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr06
cls
echo.
echo.
echo AltSynn \ Error 06
echo.
echo AltSynn was unable to open the file with MuseScore.
echo MuseScore may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr07
cls
echo.
echo.
echo AltSynn \ Error 07
echo.
echo AltSynn was unable to open the file with Anvil Studio.
echo Anvil Studio may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main

:errscr08
cls
echo.
echo.
echo AltSynn \ Error 08
echo.
echo AltSynn was unable to open the file with Windows Media Player.
echo Windows Media Player may be not installed, or AltSynn
echo doesn't support your system.
echo.
echo [Any] Return to mainmenu
pause>nul
goto main




:quit
exit


===== =====


Report •

#15
August 9, 2011 at 07:28:57
Thanks man!

And how do make it save %filesearch% to load it on next startup? I think it should be like:

===== =====
@echo off
setlocal enabledelayedexpansion
if exist filesearch.bat (
for /f "usebackq delims=" %%a in (filesearch.bat) do (
set filesearch==%%a
)
)

.....

echo %filesearch%>filesearch.bat
exit
===== =====

--randomray


Report •

#16
August 9, 2011 at 23:40:58
Yeah that should do it, just set the default before the if statement, that way it will be overwritten by the value in file and default if none.

Report •

#17
August 10, 2011 at 04:35:14
Nope, didn't work.
BTW where will it be saved?

Report •

#18
August 10, 2011 at 05:02:21
Yes it works! I had to do:

===== =====
@echo off
SetLocal EnableDelayedExpansion

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

cd %temp%
if exist AltSynn_listdir cd AltSynn_listdir
if exist filesearch.txt (
for /f "usebackq delims=" %%a in (filesearch.txt) do (
set filesearch==%%a
)
)

...

SetLocal EnableDelayedExpansion

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

cd %temp%
if exist AltSynn_listdir cd AltSynn_listdir
if exist filesearch.txt (
for /f "usebackq delims=" %%a in (filesearch.txt) do (
set filesearch==%%a
)
)

...

:quit
echo %filesearch%>filesearch.txt
exit

Anyway, my script is now all done, thank you Judago!


Report •

#19
August 10, 2011 at 05:06:02
IT'll be saved in %temp%\altsynn_listdir
Sorry I messed up the previous post - what I meant is:

===== =====

@echo off
SetLocal EnableDelayedExpansion

set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"

cd %temp%
if exist AltSynn_listdir cd AltSynn_listdir
if exist filesearch.txt (
for /f "usebackq delims=" %%a in (filesearch.txt) do (
set filesearch==%%a
)
)

...

:playscr0
color 70
mode 85,35

rem Delimited list of dir search strings
rem Subfolders are also searched


2>nul del /q "%temp%\%~n0_listdir"
2>nul md "%temp%\%~n0_listdir"
pushd "%temp%\%~n0_listdir"

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set listfiles=0
set linecnt=0
set selfile=1

for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a
for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
set /a linecnt=^(linecnt %% 12^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo Watching: %filesearch%
echo [Z] Previous, [X] Refresh, [C] Next, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n
set selection=%errorlevel%
if %errorlevel% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file="%%b"
)
if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz1
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q "%temp%\%~n0_listdir"
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0


:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz0
)
if errorlevel 2 goto main
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

:configscrz1
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz1
)
if errorlevel 2 goto playscr0
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)

echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

...

:quit
echo %filesearch%>filesearch.txt
exit
===== =====
Thanks again!

-- randomray


Report •

#20
August 10, 2011 at 23:23:32
✔ Best Answer
Ok, I think I understand....

@echo off
SetLocal EnableDelayedExpansion

Set tempdir="%temp%\%~n0_Listdir\%random%"
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
for %%a in ("#1=Q" "#2=W" "#3=E" "#4=R" "#5=T" "#6=Y" "#7=U") do set %%~a
for %%a in ("#8=I" "#9=O" "#10=P" "#11=A" "#12=S") do set %%~a


if exist "%~dp0\filesearch.txt" (
    for /f "usebackq delims=" %%a in ("%~dp0\filesearch.txt") do (
        set filesearch==%%a
    )
)


:playscr0
color 70
mode 85,35

2>nul del /q %tempdir%
2>nul md %tempdir%
pushd %tempdir%

:refrscr0
cls
mode 85,35
echo.
echo.
echo Loading files, standby...

set listfiles=0
set linecnt=0
set selfile=1


for /f "tokens=*" %%a in ('dir /s /b %filesearch%') do (
set /a linecnt=^(linecnt %% 12^) + 1
if !linecnt!==1 (
set /a listfiles+=1
type nul > list!listfiles!.txt
)
for %%b in (!linecnt!) do >> list!listfiles!.txt echo [!#%%b!] %%a
)

:selscr0
cls
echo.
echo AltSynn \ Songlibrary
echo.
echo.
echo Page %selfile% of %listfiles%
echo.

type list%selfile%.txt

echo.
echo Watching: %filesearch%
echo [Z] Previous, [X] Refresh, [C] Next, [B] Configure, [M] Exit to mainmenu

choice /c:QWERTYUIOPASZCXBM /n
set selection=%errorlevel%
if %errorlevel% lss 13 (
for /f "tokens=1*" %%a in ('echo * *^&findstr /b "\[!#%selection%!\]" list%selfile%.txt') do (
set file="%%b"
)
if !file!=="*" (goto selscr0) else goto filescr0
)
if %errorlevel%==13 if %selfile% gtr 1 (set /a selfile-=1) else set selfile=%listfiles%
if %errorlevel%==14 if %selfile% lss %listfiles% (set /a selfile+=1) else set selfile=1
if %errorlevel%==15 goto refrscr0
if %errorlevel%==16 goto configscrz1
if %errorlevel%==17 goto main
goto selscr0

:filescr0
color 71
popd
rd /s /q %tempdir%
set
cls
echo.
echo AltSynn \ Send file
echo.
echo !file!
echo.
echo Send file to...
echo.
echo [S]ynthesia
echo.
echo [M]useScore
echo [A]nvil Studio
echo [W]indows Media Player
echo.
echo.
echo [Z] Return to library
echo [X] Return to mainmenu
echo.
choice /c:SMAWZX
if errorlevel 6 goto main
if errorlevel 5 goto playscr0
if errorlevel 4 goto sendfilewmp
if errorlevel 3 goto sendfileast
if errorlevel 2 goto sendfilemus
if errorlevel 1 goto sendfilesyn


:sendfilesyn
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Synthesia...
echo Close Synthesia to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Synthesia" cd "Synthesia"
if exist "Synthesia.exe" start Synthesia.exe !file!
goto filescr0

:sendfilemus
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with MuseScore...
echo Close MuseScore to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "MuseScore" cd "MuseScore"
if exist "bin" cd "bin"
if not exist "mscore.exe" goto errscr06
if exist "mscore.exe" start mscore.exe !file!
goto filescr0

:sendfileast
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Anvil Studio...
echo Close Anvil Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Anvil Studio" cd "Anvil Studio"
if not exist "astudio.exe" goto errscr07
if exist "astudio.exe" start astudio.exe !file!
goto filescr0

:sendfilewmp
cls
echo.
echo.
echo AltSynn \ Send file
echo.
echo Executing !file! with Windows Media Player...
echo Close Windows Media Player Studio to continue with AltSynn

cd /d %systemdrive%\
if exist "Program Files (x86)" cd "Program Files (x86)"
if exist "Program Files" cd "Program Files"
if exist "Windows Media Player" cd "Windows Media Player"
if not exist "wmplayer.exe" goto errscr08
if exist "wmplayer.exe" start wmplayer.exe !file!
goto filescr0


:configscrz0
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz0
)
if errorlevel 2 goto main
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)
> "%~dp0\filesearch.txt" echo %filesearch%



echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

:configscrz1
mode 85,25
cls
echo.
echo AltSynn \ Songlibrary \ Settings
echo.
echo Watched folders: %filesearch%
echo.
echo [I]nitialize
echo [M]odify
echo [R]eturn
choice /c:mri /n
if errorlevel 3 (
set filesearch="%userprofile%\documents\*.mid";"%userprofile%\desktop\*.mid"
goto configscrz1
)
if errorlevel 2 goto playscr0
if errorlevel 1 (
echo.
echo Type the paths of the folders to be watched in quotes and separated by semicolons.
echo Use *.mid as extension. F.e. "%userprofile%\desktop\*.mid";"D:\myfiles\*.mid"
set /p filesearch="Use [Enter] to apply: "
)
> "%~dp0\filesearch.txt" echo %filesearch%


echo.
echo New value set.
echo [Q] Goto mainmenu
echo [W] Goto songlibrary
choice /c:qw /n
if errorlevel 2 goto playscr0
if errorlevel 1 goto main

...

:quit
exit


Report •


Ask Question