Hi,
I want the person to choose which drive to make a file in. It lists the drives (my previous question!), they choose one, and then the batch sets their answer as a variable. Then, it changes to the directory they inputted and makes the file there.
Could you tell me how to do so?
Thanks for the help,
Rileyh
Listing all drives and making user select one
Moderator: DosItHelp
Re: Listing all drives and making user select one
You could use the WMIC command.
Regards
aGerman
Code: Select all
@echo off
setlocal enabledelayedexpansion
set /a n=0
echo Number Drive Name
for /f "tokens=2 delims==" %%i in ('wmic logicaldisk get name /value') do (
set /a n+=1
echo !n! %%i
set "d_!n!=%%i"
)
:loop
echo(
set "num="
set /p "num=Choose a number: "
if defined d_%num% (
set "drive=!d_%num%!"
) else (
echo This drive doesn't exist^^!
goto :loop
)
endlocal &set "drive=%drive%"
echo(
echo You have chosen %drive%.
pause
Regards
aGerman
Re: Listing all drives and making user select one
aGerman,
Thank you for the code. Now I am going to spend a few hours understanding what you have posted!
Could you tell me how to, at the end of the code you posted, change directory to the variable "drive"?
Thanks again for the code,
Rileyh
Thank you for the code. Now I am going to spend a few hours understanding what you have posted!
Could you tell me how to, at the end of the code you posted, change directory to the variable "drive"?
Thanks again for the code,
Rileyh
Re: Listing all drives and making user select one
@Ed Dyreen,
Thanks for the post. It worked well. What do you by "the stack" (please excuse my poor batch skills!)
Regards,
Rileyh
Thanks for the post. It worked well. What do you by "the stack" (please excuse my poor batch skills!)
Regards,
Rileyh
Re: Listing all drives and making user select one
'
In computer science, a stack is a last in, first out (LIFO) abstract data type and data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack, or initializes the stack if it is empty. If the stack is full and does not contain enough space to accept the given item, the stack is then considered to be in an overflow state. The pop operation removes an item from the top of the stack. A pop either reveals previously concealed items, or results in an empty stack, but if the stack is empty then it goes into underflow state (It means no items are present in stack to be removed). The stack top operation gets the data from the top-most position and returns it to the user without deleting it. The same underflow state can also occur in stack top operation if stack is empty.
http://en.wikipedia.org/wiki/Stack_%28data_structure%29
In computer science, a stack is a last in, first out (LIFO) abstract data type and data structure. A stack can have any abstract data type as an element, but is characterized by only three fundamental operations: push, pop and stack top. The push operation adds a new item to the top of the stack, or initializes the stack if it is empty. If the stack is full and does not contain enough space to accept the given item, the stack is then considered to be in an overflow state. The pop operation removes an item from the top of the stack. A pop either reveals previously concealed items, or results in an empty stack, but if the stack is empty then it goes into underflow state (It means no items are present in stack to be removed). The stack top operation gets the data from the top-most position and returns it to the user without deleting it. The same underflow state can also occur in stack top operation if stack is empty.
http://en.wikipedia.org/wiki/Stack_%28data_structure%29
Re: Listing all drives and making user select one
@Ed Dyreen,
Thanks for the example.
Rileyh
Thanks for the example.
Rileyh