Batch File Loop

Hello All

I want to create a batch file that repeats a command four times.  I have some freeware that ejects USB connected drives based on their drive letter, therefore I want to run this command:

removedrive.exe e: -E -W:1000  (where e: is the drive letter)

then I want to run:

removedrive.exe f: -E -W:1000  (where f: is the drive letter)

etc, up to h: and then exit.

I assume some sort of loop would be required?  Any help much appreciated.

Cheers
V.
LVL 1
vision_onAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That fits into one command line: for %a in (E: F: G: H:) do (removedrive.exe %a -E -W:1000)
In a batch file, use double percent signs: for %%a in (E: F: G: H:) do (removedrive.exe %%a -E -W:1000)
0
vision_onAuthor Commented:
Thanks oBdA

You will have to spell it out for me I am not very good at this stuff, so in a batch file, the syntax should be:

For %%a In (E: F: G: H:) Do (removedrive.exe %%a -E -W:1000)

Do I need the brackets round the drive letters and command?

Cheers
V.
0
oBdACommented:
You will need the brackets around the drive letters.
Syntactically, the brackets around the command aren't required in this case.
If you want to spread out the command over several lines, though, they're required, for example like this:
@echo off
For %%a In (E: F: G: H:) Do (
	echo Removing drive %%a
	removedrive.exe %%a -E -W:1000
)

Open in new window

If you want to look into scripting (batch and other languages), check out http://www.robvanderwoude.com
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vision_onAuthor Commented:
Excellent thanks very much for your help.

V.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.