Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

batch file menu?

156 views
Skip to first unread message

Harry Potter

unread,
Jun 19, 2016, 5:44:37 AM6/19/16
to
Hi! I want to be able to select a file or directory from an NT batch file. How do I do that? What about static selections (i.e. select from several constant options?

Petr Laznovsky

unread,
Jun 19, 2016, 7:51:34 AM6/19/16
to
Dne 19.6.2016 v 11:44 Harry Potter napsal(a):
> Hi! I want to be able to select a file or directory from an NT batch file. How do I do that? What about static selections (i.e. select from several constant options?
>

It depends:

If you want to do something like windows explorer, searching through whole filesystem, it will be
realy hard job. But if you want to choode from few predefined paths (files) you can do something
like this:

set "_path;1=C:\windows"
set "_path;2=C:\utils"
for /f "tokens=2,3 delims=;=" %%a in ('set _path') do echo %%a. %%b
echo.
echo Insert option number and pres ENTER:
set /p option=
for /f %%a in ("%option%") do call set choosed_path=%%_path;%option%%%
echo %choosed_path%

L.

foxidrive

unread,
Jun 19, 2016, 6:03:21 PM6/19/16
to
On 19/06/2016 19:44, Harry Potter wrote:
> Hi! I want to be able to select a file or directory from an NT batch file. How do I do that? What about static selections (i.e. select from several constant options?
>


What kind of selection method are you aiming at?

Here's a gui method to get a file.

@echo off
set "var=Add-Type -AssemblyName System.windows.forms"
set "var=%var%|Out-Null;$f=New-Object"
set "var=%var% System.Windows.Forms.OpenFileDialog"
set "var=%var%;$f.InitialDirectory=''"
set "var=%var%;$f.Filter='Positive Registry Files (*.reg)"
set "var=%var%||All Files (*.*)|*.*';$f.showHelp=$true;"
set "var=%var%$f.ShowDialog()|Out-Null;$f.FileName"

for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
set chooser_file=powershell "%var%"
)

for /f "delims=" %%I in ('%chooser_file%') do set "regfile=%%I"
echo "%regfile%"
pause


Harry Potter

unread,
Jun 20, 2016, 5:51:19 AM6/20/16
to
I thank both of you for your responses. The purpose of the menu is to display the subdirectories within a directory for the purpose of making a new directory out of the old directory. They should be displayed in the console, and the user should use the cursor keys to select the directory. I prefer two columns.

BTW, when I'm finished, does anybody here want the batch file? :)

(PeteCresswell)

unread,
Jun 20, 2016, 10:53:56 AM6/20/16
to
Per Harry Potter:
>BTW, when I'm finished, does anybody here want the batch file? :)

Yes!... Thanks for thinking of us....

How about just post it here as a followup message?
--
Pete Cresswell

Pedro M

unread,
Jun 20, 2016, 12:06:08 PM6/20/16
to

Here's a menu I did once, it may not be what you need but maybe some of you can take some ideas from it.
It's a menu to "Supermodel", a SEGA Model 3 emulator, which is a command line program.

It works with DOS alone with no aditional programs like powershell, and it displays in a single column the rom list, which will be automatically divided in 2 columns if the rom list gets bigger, and it will pause the 2 column listing if it gets even bigger (I didn't test this one fully, though).

The working instructions are as follow (in the batch both them and the comments are in portuguese, I didn't have the patiente to translate them):

// In the list, next to each name there's a number, you press the number to execute the game
// If you press the number followed by '-' e.g. "6-" it will delete that rom file (you will have to remove the game entry from the batch though)
// Pressing 'X' exits the menu


Editing instructions:
The Rom titles and respective zip filename are written in the beggining of the menu batch, and it has the following format:
~~<name of the game> <spaces, not mandatory just for organization> @@<rom name(zip file without the extension)>

Of course you can adapt this to other stuff instead of roms.

***Here's the batch:
(NOTE: the strange char next to "nul set /p =." is the DOS backspace so it can remove the dot at the left. To properly write this char you have to use some DOS text tool ("Edit" from XP, for instance) and press Ctrl P + Ctrl H
============================================================================

@echo off
GOTO INICIO
rem ####### ESCREVER '~~', O TíTULO DO JOGO, espaços, '@@', E O NOME DA ROM
~~Daytona USA @@daytona
~~Daytona 2 USA @@daytona2
~~Daytona 2 USA Power Edition @@dayto2pe
~~House of the Dead 2 (não) @@hotd2
~~L.A. Machineguns @@lamachin
~~Le Mans 24 @@lemans24
~~The Lost World @@lostwsga
~~The Ocean Hunter @@oceanhun
~~Scud Race @@scud
~~Scud Race Plus (Revision A) @@scudplus
~~Ski Champ @@skichamp
~~Sega Rally 2 DX @@srally2x
~~Star Wars Trilogy @@swtrilgy
~~Time Crisis 2 @@timecrs2
~~Time Crisis 3 @@timecrs3
~~Time Crisis 4 @@timecrs4



:INICIO
set Titulo_MENU=// SUPERMODEL // A Sega Model 3 Arcade Emulator
set pasta_ROMS=Roms_supermodel

setlocal EnableDelayedExpansion
set /A index=0
TITLE %Titulo_MENU%
for /f "delims=" %%u in ('findstr /B "~~" "%~NX0"') do (
set /a index=!index!+1
set titulo_!index!=%%u
)
:MENU
COLOR 0A
set jogo=
set jogo_existe=
set apagar=NAO
Set /a index_MAIS_UM=%index%+1
set /a div_screen=%index%-%index%/2+1
set /a modul=%index% %% 2
set /a linhas=%INDEX%-8
IF %INDEX% GTR 36 (cls&mode con: cols=84 lines=%linhas%)
ECHO %Titulo_MENU%
IF %INDEX% GTR 20 (echo ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ) ELSE (echo ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ)
echo JOGOS:
echo.
if %INDEX% GTR 20 (
For /L %%e in (1,1,%index%) do (
for /f "tokens=1-4 delims=@~" %%w in ('CALL echo %%TITULO_%%e:~2%%%%TITULO_!div_screen!%%') do (
IF %modul% GTR 0 if !div_screen! LEQ %index_MAIS_UM% (
IF %%e LSS 10 <nul set /p =.
<nul set /p =. %%e. %%w &if !div_screen! LEQ %index% echo ³ !div_screen!. %%y
set /A div_screen=!div_screen!+1
)
IF %modul% EQU 0 if !div_screen! LSS %index_MAIS_UM% (
IF %%e LSS 10 <nul set /p =.
<nul set /p =. %%e. %%w &if !div_screen! LEQ %index% echo ³ !div_screen!. %%y
set /A div_screen=!div_screen!+1
)
)
)
) ELSE (
For /L %%e in (1,1,%index%) do (
for /f "tokens=1,2 delims=@" %%x in ('CALL echo %%TITULO_%%e:~2%%') do IF %%e LSS 10 (Echo %%e. %%x) ELSE (Echo %%e. %%x)
)
)
if %modul% NEQ 0 echo.
if %INDEX% GTR 20 (echo.&echo X. Sair) ELSE (echo.&echo X. Sair)
IF %INDEX% GTR 20 (echo ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ) ELSE (echo ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ)
echo.&echo.
set /p JOGO="> Escolher o n§ de um jogo (escrever '-' no final para o apagar) : "
if %jogo:~-1% equ - (set "jogo=%jogo:-=%" & set apagar=sIm)
for /L %%i in (1,1,%index%) Do if %%i equ %jogo% set jogo_existe=sim
if NOT defined jogo_existe if /I %jogo% NEQ X (echo. & echo ^>^> **ERRO** Escolha inv lida! &@ping localhost -n 3 >nul &echo.&echo.&GOTO MENU)
if /I %jogo% equ x (echo.& echo // a sair... & @ping localhost -n 2 > nul & endlocal & exit /B)
echo.
echo.
For /f "tokens=1,2 delims=@" %%a in ('call ECHO %%Titulo_%jogo%:~2%%') do CALL :JOGAR %%b "%%a"
GOTO MENU


:: ################################ SUB-ROTINAS ###########################################
:JOGAR
IF NOT EXIST %pasta_ROMS%\%1.zip (ECHO.&ECHO ^>^> ##ERRO## A ROM %1.zip NÇO EXISTE! & @ping localhost -n 3 > nul & GOTO MENU)
set "Nome=%~2"
set "nome=%NOME: =%"
IF "%nome:~-1%"==" " SET "Nome=%nome:~0,-1%"
set "nome=%NOME:(=[%"
set "nome=%NOME:)=]%"
if /I %apagar% neq SIM (
Echo.&echo ^>^> A iniciar o jogo ®%NOME%¯... & @ping localhost -n 3 > nul
REM del nvram\%1.nv
supermodel.exe %pasta_ROMS%\%1.zip -res=1024,768 -fullscreen -sound-volume=60 -music-volume=60
REM del error.log
) eLSE (CALL :APAGAR %1 "%nome%")
goto:eof
::-----------------------------------------
:APAGAR
color 0c
echo.& ECHO ^>^> Apagar ®%~2¯ DE CERTEZA ?
set /p apagar=">> (escrever DEL para apagar, qq outra coisa para cancelar): "
echo.&IF /I %APAGAR% EQU DEL (
del %pasta_ROMS%\%1.zip
del NVRAM\%1.nv
if exist Saves\%1.* del Saves\%1.*
if EXIST %pasta_ROMS%\%1 ( ^>^> ##ERRO## NÇO FOI POSSIVEL APAGAR O FICHEIRO) ELSE (echo ^> o jogo ®%~2¯ ^(rom: %1^) foi apagado)
) ELSe (echo ^> Elimina‡Æo cancelada.)
echo ^> A voltar ao menu... & @ping localhost -n 3 > nul & ECHO.&ECHO.&ECHO.
GOTO :EOF

Harry Potter

unread,
Jun 21, 2016, 5:28:28 AM6/21/16
to
The menu has to be dynamic and allow the user to select a choice with either the keyboard or the mouse. Basically, it is to display the directories within a directories and allow the selection and creation of one. Right now, the user has to *type in* the directory. :(

Harry Potter

unread,
Jun 21, 2016, 5:29:19 AM6/21/16
to
:D Should I post what I have?

foxidrive

unread,
Jun 22, 2016, 12:49:17 AM6/22/16
to
Select with a mouse in a console screen?

It's not impossible but Windows doesn't do it out-of-the-box.
You may have to explain the way this works a little more thoroughly.

Harry Potter

unread,
Jun 22, 2016, 5:02:37 AM6/22/16
to
On Wednesday, June 22, 2016 at 12:49:17 AM UTC-4, foxidrive wrote:
>
> Select with a mouse in a console screen?
>
> It's not impossible but Windows doesn't do it out-of-the-box.
> You may have to explain the way this works a little more thoroughly.

Well, the cursor keys are okay. I just prefer this rather than typing the name fully. :)

Herbert Kleebauer

unread,
Jun 22, 2016, 6:10:50 AM6/22/16
to
On 22.06.2016 11:02, Harry Potter wrote:
> On Wednesday, June 22, 2016 at 12:49:17 AM UTC-4, foxidrive wrote:

>> Select with a mouse in a console screen?
>
> Well, the cursor keys are okay. I just prefer this rather than typing the name fully. :)

Why don't you do it the good old way: use "echo" to display the
menu:

[a] ...............
[b] ...............

[z] ...............

and then use choice to get a key press a-z


Harry Potter

unread,
Jun 22, 2016, 6:47:03 PM6/22/16
to
On Wednesday, June 22, 2016 at 6:10:50 AM UTC-4, Herbert Kleebauer wrote:
> Why don't you do it the good old way: use "echo" to display the
> menu:
>
Because the menu has to be built from the contents of a directory on run time.

foxidrive

unread,
Jun 22, 2016, 9:17:53 PM6/22/16
to
You haven't described your code or task well at all, and people make their
suggestions based upon your details.

With poor details in a programming forum it's only by random chance that
you will get the best solution. Or even one that suits the task you
haven't described.


pro...@berkeley.edu

unread,
Jun 23, 2016, 12:50:37 AM6/23/16
to
Like this?

===============BEGIN SCREEN CAPTURE=================

C:\Users\JoeUser>\cmd\demo\hpmenu \cmd\*menu*.cmd
01 ... C:\cmd\demo\BRMenu.cmd
02 ... C:\cmd\demo\ctextmenu.cmd
03 ... C:\cmd\demo\DisplayAMenu.cmd
04 ... C:\cmd\demo\hpmenu.cmd
05 ... C:\cmd\demo\MyFirstMenu.cmd
06 ... C:\cmd\demo\MyMainMenu.cmd
07 ... C:\cmd\demo\mymenu.cmd
08 ... C:\cmd\demo\MySnazzyMenu.cmd
09 ... C:\cmd\test\filemenu.cmd
10 ... C:\cmd\test\mainmenu1.cmd
Your choice? 04

You selected C:\cmd\demo\hpmenu.cmd

@echo off
setlocal enabledelayedexpansion
set /a n = 100
for /f "tokens=*" %%x in ('dir /s /b %*') do (
set /a n += 1
set S!n!=%%x
echo/!n:~1! ... %%x
)
set /p choice="Your choice? "
if not defined choice goto :EOF
echo/
echo/You selected !S1%choice%!
echo/
more !S1%choice%!
goto :EOF
==============END SCREEN CAPTURE =================

Phil Robyn

Harry Potter

unread,
Jun 23, 2016, 5:29:42 AM6/23/16
to
On Wednesday, June 22, 2016 at 9:17:53 PM UTC-4, foxidrive wrote:
> You haven't described your code or task well at all, and people make their
> suggestions based upon your details.
>
> With poor details in a programming forum it's only by random chance that
> you will get the best solution. Or even one that suits the task you
> haven't described.

I'm sorry. :( The file, when run, displays all the directories in a given directory, asks the user to type in the name of the directory to copy, then copies the directory to the directory specified in the argument. I want the user to *select* the directory rather than *type in* the directory. Here's what I have so far:

----------------------------
@echo off
:: The folder containing the folder templates:
set curflds=c:\myprgs\folderlist
echo This batch file creates a new folder in the folder dragged onto it or
echo fed to it on the command-line.
echo.

::Prompt for the name of the new folder and retrieve it in curflds.
set /p newfld=Type in the name of the new folder:
::Switch to the folder fed to this batch file.
cd /d %1

echo.
echo The following is a list of the folder templates available on this
echo system:
echo.

dir /b/ad %curflds%
echo.
set /p oldfld=Type in the name of a folder template:
md %newfld%
cd %newfld%
xcopy /e /y %curflds%\%oldfld%\*.*
pause
-------------------------------------
Does this help?

Herbert Kleebauer

unread,
Jun 23, 2016, 10:57:40 AM6/23/16
to
On 23.06.2016 11:29, Harry Potter wrote:

> I'm sorry. :( The file, when run, displays all the directories in a given directory,
> asks the user to type in the name of the directory to copy, then copies the directory
> to the directory specified in the argument. I want the user to *select* the directory
> rather than *type in* the directory.

Phil gave you an example using "set /p", here is one using "choice":

This batch will list all subdirectories in the current directory
(max 26, but you can add A-Z and 1-9 if you need more). By pressing a
key a-z you can select one of them.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
cls
setlocal enabledelayedexpansion

set n=0
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set abc[!n!]=%%i)

set m=0

for /f "tokens=*" %%i in ('dir /ad /b ') do (
if !m! geq %n% goto :max
set /a m += 1
set dir[!m!]=%%i
call echo [%%abc[!m!]%%] %%i)

:max
set s=
for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!
set /a m += 1

choice /c %s%0 /cs /n /m "Which one [press 0 to abort] :"
if errorlevel %m% echo aborted & goto :eof
call set d=%%dir[%errorlevel%]%%

echo You selected: %d%








petu...@googlemail.com

unread,
Jun 24, 2016, 7:43:59 PM6/24/16
to
Here's another example to answer the query relevant to the the topic title.

::----- START -----
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "curflds=C:\myprgs\folderlist"

If /I "%CD%" NEq "%curflds%" PushD %curflds% 2>Nul&&Set "_=T"||GoTo :EOF

Echo( Choose a template directory from the list&Echo(
For /F "Tokens=1* Delims=:" %%a In ('Dir/B/AD-S-H^|FindStr/n .*') Do (
Set "Sel%%a=%%b"
Echo( %%a. %%b)
If %_%==T PopD
Echo(
Set/P "Sel="
Set Sel|Findstr/B "Sel%Sel%=">Nul||GoTo :EndIt
Call Echo( You Selected "%curflds%\%%Sel%Sel%%%"
:EndIt
Timeout -1 1>Nul
::------ END ------

Harry Potter

unread,
Jun 24, 2016, 7:45:00 PM6/24/16
to
Thank you. That should help. :)

petu...@googlemail.com

unread,
Jun 24, 2016, 8:00:49 PM6/24/16
to
On Thursday, 23 June 2016 10:29:42 UTC+1, Harry Potter wrote:
Another alternative.
::----- START -----
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "curflds=c:\myprgs\folderlist"

If /I "%CD%" NEq "%curflds%" PushD %curflds% 2>Nul&&Set "_=T"||GoTo :EOF

Echo( Choose a template directory from the list&Echo(
For /F "Tokens=1* Delims=:" %%a In ('Dir/B/AD-S-H^|FindStr/n .*') Do (
Set "Sel%%a=%%b"
Echo( %%a. %%b)
If %_%==T PopD
Echo(
Set/P "Sel="
Set Sel|Findstr/B "Sel%Sel%=">Nul||GoTo :EndIt
Call Echo( You Selected "%curflds%\%%Sel%Sel%%%"
:EndIt
Pause>Nul
::------ END ------

petu...@googlemail.com

unread,
Jun 24, 2016, 8:18:06 PM6/24/16
to
On Thursday, 23 June 2016 10:29:42 UTC+1, Harry Potter wrote:
>
>
Here's an alternative to Phil and Herberts excellent solutions for you.

foxidrive

unread,
Jun 24, 2016, 9:26:25 PM6/24/16
to
On 24/06/2016 09:08, Harry Potter wrote:
> Thank you. That should help. :)

I'm only replying here Harry to comment on an aspect of Usenet in these
newsgroups.

Your words above show no context of the messages before them, so nobody
knows what you are referring to or who has helped you.

It helps to quote small passages and reply below them to give context to
your words.


I'm aware that it's harder for people who use Google to post, but the
Windows clipboard can be used to capture some text and paste it into your
reply too.


Back in the old days when everyone used newsreader software the arguments
were if quoting should be done at the top, the bottom, or inline. Many fun
times were had, and flaming happened regularly.

But flaming in the batch groups was far rarer. It must be because the
higher calibre of people who write batch files. :)

Cheers
foxi




pro...@berkeley.edu

unread,
Jun 25, 2016, 12:28:45 AM6/25/16
to
Thank you for posting! I don't regard what I posted as a solution because
I was never clear about what the specs/requirements were. Directories or
files? And what was supposed to happen? With a mouse, no less . . . .

I was only hoping that Harry would be able to glean some useful insight
into dynamically getting a list of objects of interest and then selecting
an object from said list.

--
Phil R.

Harry Potter

unread,
Jun 25, 2016, 9:51:31 AM6/25/16
to
On Saturday, June 25, 2016 at 12:28:45 AM UTC-4, pro...@berkeley.edu wrote:
> Thank you for posting! I don't regard what I posted as a solution because
> I was never clear about what the specs/requirements were. Directories or
> files? And what was supposed to happen? With a mouse, no less . . . .
>
> I was only hoping that Harry would be able to glean some useful insight
> into dynamically getting a list of objects of interest and then selecting
> an object from said list.
>
I'm sorry. I think one of you helped, though. I just need to create a new folder in a given folder of a given name and add some files to it automatically. Sort of like a folder template. The batch file works by creating the folder and adding the contents of a special folder. The batch file as is is okay. I just wanted to ease its usage. I already copied the first batch file selected and plan to analyze and implement it. No further response is needed.

Harry Potter

unread,
Sep 18, 2016, 6:24:51 AM9/18/16
to
Hi, again. I finally tested the batch file from here I selected. At the choice line, the batch file gives the following error:
-------------------
ERROR: Invalid argument/option - 'b'.
Type "CHOICE /?" for usage.
-------------------
Here's the batch file:
-------------------
@echo off
cls
setlocal enabledelayedexpansion

set n=0
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set abc[!n!]=%%i)

set m=0

for /f "tokens=*" %%i in ('dir /ad /b C:\MyPrgs\folderlist ') do (
if !m! geq %n% goto :max
set /a m += 1
set dir[!m!]=%%i
call echo [%%abc[!m!]%%] %%i)

:max
set s=
for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!
set /a m += 1

choice /c %s%0 /cs /n /m "Which one [press 0 to abort] :"
if errorlevel %m% echo aborted & goto :eof
call set d=%%dir[%errorlevel%]%%

echo You selected: %d%
pause
--------------------
Here's the output:
--------------------
[a] Happy
[b] Hidden64_SimpIO Ex
[c] HiMem64 8k Ex
ERROR: Invalid argument/option - 'b'.
Type "CHOICE /?" for usage.
aborted

Harry Potter

unread,
Sep 18, 2016, 7:21:20 AM9/18/16
to
I changed the for loop that records the choices as follows:
---------------------------
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set tta=%%i
set cho=%cho%%%i
::echo .%cho%
set abc[!n!]=%%i)
::set abc=%abc%%%i
---------------------------
I'm thinking of just writing the a-z characters literally in the choice command: it will process invalid choices but will also be easier and should work. :)

Harry Potter

unread,
Sep 18, 2016, 8:04:15 AM9/18/16
to
Well...this is what I have so far, but the line "set d=%curflds%\%dir[!n!]%" doesn't display the subdirectory properly: everything of the path but the subfolder selected is displayed. Also, a later line displays "The syntax of the command is incorrect." What's wrong? :(
-----------------------------
@echo off
cls
setlocal enabledelayedexpansion
::setlocal ENABLEEXTENSIONS

set abc=
set cho=
set n=0

set curflds=c:\myprgs\folderlist

cd /d %curflds%

echo This batch file creates a new folder in the folder dragged onto it or
echo fed to it on the command-line.
echo.


for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set tta=%%i
set cho=%cho%%%i
::echo .%cho%
set abc[!n!]=%%i)
::set abc=%abc%%%i

set m=0

echo .%cho%

for /f "tokens=*" %%i in ('dir /ad /b C:\MyPrgs\folderlist ') do (
::if !m! geq %n% goto :max
set /a m += 1
set dir[!m!]=%%i
call echo [%%abc[!m!]%%] %%i
)

:max
::set s=
::for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!
::set /a m += 1

choice /c abcdefghijklmnopqrstuvwxyz0 /cs /n /m "Choose template folder, or press 0 to abort:"
::if errorlevel %m% echo aborted & goto exit
if errorlevel 26 echo aborted & goto exit
set n=%errorlevel%
set d=%curflds%\%dir[!n!]%

echo You selected: %d%
set /p newdir="Type in the name of the new folder: "

cd /d %1

md %newfld%
cd %newfld%
xcopy /e /y %curflds%\%d%\*.*

:exit
pause
----------------------------

Herbert Kleebauer

unread,
Sep 18, 2016, 8:41:20 AM9/18/16
to
On 18.09.2016 12:24, Harry Potter wrote:
> Hi, again. I finally tested the batch file from here I selected. At the choice line, the batch file gives the following error:
> -------------------
> ERROR: Invalid argument/option - 'b'.
> Type "CHOICE /?" for usage.
> -------------------
> Here's the batch file:
> -------------------
> @echo off
> cls
> setlocal enabledelayedexpansion
>
> set n=0
> for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
> set /a n += 1
> set abc[!n!]=%%i)
>
> set m=0
>
> for /f "tokens=*" %%i in ('dir /ad /b C:\MyPrgs\folderlist ') do (
> if !m! geq %n% goto :max
> set /a m += 1
> set dir[!m!]=%%i
> call echo [%%abc[!m!]%%] %%i)
>
> :max
> set s=
> for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!


There is a trailing space in the above line which you have to remove.


JJ

unread,
Sep 18, 2016, 9:03:30 AM9/18/16
to
Hear the echo and the false path shall be revealed.

Harry Potter

unread,
Sep 18, 2016, 7:51:54 PM9/18/16
to
Here's the latest version of the batch file:
---------------------------------
@echo off
cls
setlocal enabledelayedexpansion
::setlocal ENABLEEXTENSIONS

set abc=
set cho=
set n=0

set curflds=c:\myprgs\folderlist

cd /d %curflds%

echo This batch file creates a new folder in the folder dragged onto it or
echo fed to it on the command-line.
echo.


for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set tta=%%i
set cho=%cho%%%i
::echo .%cho%
set abc[!n!]=%%i)
::set abc=%abc%%%i

set m=0

echo .%cho%

for /f "tokens=*" %%i in ('dir /ad /b C:\MyPrgs\folderlist') do (
if !m! geq %n% goto :max
set /a m += 1
set dir[!m!]=%%i
call echo [%%abc[!m!]%%] %%i
)

:max
set s=
for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!
set /a m += 1

choice /c abcdefghijklmnopqrstuvwxyz0 /cs /n /m "Choose template folder, or press 0 to abort:"
::if errorlevel %m% echo aborted & goto exit
if errorlevel 26 echo aborted & goto exit
set n=%errorlevel%
set d=%curflds%\%dir[!%n%!]%

echo You selected: %d%
set /p newdir="Type in the name of the new folder: "

cd /d %1

md %newfld%
cd %newfld%
xcopy /e /y %curflds%\%d%\*.*

:exit
pause
----------------------------------
Now, the line that starts with "set d=" gives improper results: at it stands, it gives me the errorlevel # instead of the chosen subdirectory. :(
0 new messages