Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mbgf23
Posts: 5
Joined: 28 Dec 2010 06:59

Help

#1 Post by mbgf23 » 28 Dec 2010 07:14

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 :DOWN
set empleado=%emp%.pdf
set copia=B:\"Personal\Massimiliano\Nueva carpeta\%empleado%"
copy %copia% %carpeta%
goto :EMPLIN
:DOWN
cd C:\
--------------------------------------

Please help and if you find some way to improve my scrip is welcome!!!
Thanks in advance.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help

#2 Post by aGerman » 28 Dec 2010 08:06

Try:

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

mbgf23
Posts: 5
Joined: 28 Dec 2010 06:59

Re: Help

#3 Post by mbgf23 » 28 Dec 2010 09:07

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

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Help

#4 Post by ChickenSoup » 28 Dec 2010 10:09

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help

#5 Post by aGerman » 28 Dec 2010 10:15

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

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Help

#6 Post by ChickenSoup » 28 Dec 2010 10:22

aGerman. I like your way better than mine. :mrgreen:

mbgf23
Posts: 5
Joined: 28 Dec 2010 06:59

Re: Help

#7 Post by mbgf23 » 28 Dec 2010 10:39

Thank you very much to both of you! It works perfect aGerman!!!
Thanks again!!!

Post Reply