Hello,
Sorry if I am not clear enough or my enghlish is not goog :S.
I am kind of new in batch scripting and after several day reading a los of pages and websites I reach here where I think is the most usefull, and here is my question.
I need a batch file that creates a menu based in a list of folders (dir).
Example:
----
Menu: Select the opcion you want:
----
1- Folder 1
2- Folder 2
'
'
And so on.
The script also do another stuff which I have solved...
Down here is my script;
-----------------------------
@echo off
setlocal enabledelayedexpansion
set title=Menu Jimena
TITLE %title%
:EMPRIN
echo ::--------------------------------------------::
echo ::Recuerde Ingresar el nombre de la empresa ::
echo ::tal cual el nombre de la carpeta destino. ::
echo ::--------------------------------------------::
set /p name= Ingrese nombre de empresa: rem here the user inputs the name of the folder which I want to be automated so rem there is no place for errors. if they have only the option they can not make mistakes.
set destino=c:\"Pruebas\%name%"
If NOT EXIST %destino% goto :EMPRIN
set /p mes= Ingrese mes: rem user inputs the name of the folder to be created for copy the files.
cd %destino%
mkdir %mes% rem create the new folder for the files
cd %mes%
set carpeta=%destino%\%mes%\
:EMPLIN
echo ::--------------------------------------------::
echo ::Digitar "Fin" para no ingresar mas empleados::
echo ::--------------------------------------------::
set /p emp=Ingrese N Empleado: rem user input part of the name of the files to be copied.
If %emp% == Fin goto OWN
set empleado=%emp%.pdf
set copia=B:\"Personal\Massimiliano\Nueva carpeta\%empleado%"
copy %copia% %carpeta%
goto :EMPLIN
OWN
cd C:\
--------------------------------------
Please help and if you find some way to improve my scrip is welcome!!!
Thanks in advance.
Help
Moderator: DosItHelp
Re: Help
Try:
Regards
aGerman
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "f_1=Folder 1"
set "f_2=Folder 2"
set "f_3=anotherFolder"
echo ----
echo Menu:
echo ----
echo 1- %f_1%
echo 2- %f_2%
echo 2- %f_3%
:errorLoop
set "num="
set "selectedFolder="
set /p "num= Select the number for the folder you want: "
set "selectedFolder=!f_%num%!"
if not defined selectedFolder goto errorLoop
echo(
echo Your selection was "%selectedFolder%".
pause>nul
Regards
aGerman
Re: Help
Thank you very much for the fast replya aGerman.
That helps a lot, may be i was not clear enough in my post (my english is a crap sorry againg about that)
I need that the menu is feeded by a dir command.
Example:
I have a folder called Test, and above that I have; Folder 1, Folder 2, Folder 3, Folder 4...etc
So, I need a dinamic menu, created with the dir command output of the Test folder.
Thanks again and sorry for the misunderstood :S
That helps a lot, may be i was not clear enough in my post (my english is a crap sorry againg about that)
I need that the menu is feeded by a dir command.
Example:
I have a folder called Test, and above that I have; Folder 1, Folder 2, Folder 3, Folder 4...etc
So, I need a dinamic menu, created with the dir command output of the Test folder.
Thanks again and sorry for the misunderstood :S
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Help
Try this one. May not be the exact best way to do it. but, it seems to work:
Code: Select all
@echo off
setlocal enabledelayedexpansion
echo ----
echo Menu:
echo ----
set int=0
echo.>%temp%\folder.txt
for /f "tokens=*" %%a in ('dir /ad/b') do set /a int+=1 > nul & echo.!int! - %%a & echo.## !int! - %%a>>%temp%\folder.txt
echo.
:errorLoop
set /p "num=Select the number for the folder you want: "
FINDSTR /C:"## %num% " %temp%\folder.txt >nul 2>&1 || goto errorLoop
for /f "tokens=2* delims=-" %%i in ('FINDSTR /C:"## %num% " %temp%\folder.txt') do set yourfolder=%%i
set yourfolder=%yourfolder:~1%
echo %yourfolder%
del %temp%\folder.txt
pause>nul
Re: Help
Code: Select all
@echo off
setlocal enabledelayedexpansion
:: Change to your path:
set "rootFolder=C:\whereever\test"
echo ----
echo Menu:
echo ----
cd /d "%rootFolder%"
set /a n=0
for /f "delims=" %%a in ('dir /ad /b') do (
set /a n+=1
set "f_!n!=%%~a"
echo !n!- %%~a
)
:errorLoop
set "num="
set "selectedFolder="
set /p "num= Select the number for the folder you want: "
set "selectedFolder=!f_%num%!"
if not defined selectedFolder goto errorLoop
echo(
echo Your selection was "%selectedFolder%".
pause
Hope that helps
aGerman
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Help
aGerman. I like your way better than mine.