Rawns Posted January 27, 2011 Posted January 27, 2011 Possibly a simple task but I can't seem to find out how to do this! Two files: Drive.txt Command.bat Drive.txt simply contains "D:" How can I get the batch file to read "D:" in the drive.txt file and set it as a variable?
Guest TheLibrarian Posted January 27, 2011 Posted January 27, 2011 The for command is your friend there.
srochford Posted January 27, 2011 Posted January 27, 2011 A bit more detail - you just want the single line: for /f %%i in (drive.txt) do set drive=%%i 1
Rawns Posted January 27, 2011 Author Posted January 27, 2011 Thanks guys! One last search in Google pulled this up: set /p Drive= Seems to work a treat.
somabc Posted January 27, 2011 Posted January 27, 2011 This is a good reference for commands like FOR or SET Windows CMD Commands 1
Guest TheLibrarian Posted January 27, 2011 Posted January 27, 2011 Thanks guys! One last search in Google pulled this up: set /p Drive= Seems to work a treat. That will work as long as you don't have a requirement for processing more than one line.
Rawns Posted January 27, 2011 Author Posted January 27, 2011 That will work as long as you don't have a requirement for processing more than one line. Nope, it will only ever be one line, but I can see this being useful so will explore the for command a bit more too.
somabc Posted January 27, 2011 Posted January 27, 2011 Didn't know about set /p and reading from a file this may come in useful!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now