Computing.Net > Forums > Programming > Batch file FOR LOOP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file FOR LOOP

Reply to Message Icon

Name: shrads
Date: October 20, 2004 at 07:14:30 Pacific
OS: XP
CPU/Ram: 256
Comment:

Hi,
I need to run a particular se of commands repetatively for some number of times provided by userin for loop.
I am doing it this way
user input the no of arguments and arguments
i.e 3 d:\\input.txt d:\\dir1 d:\\dir2
my batch file
set k=%%1
for %%i(%%(k-2)
do
cd %%(k-1) //comment: i want to go to dir1
java tsafe.main.Main //command to be run
copy %%i d://dir3//test1.txt
serve.py //command to be run
done
but nothing is working
i was doing this shell script earlier with cygwin .
Any help greatly appreciated
Thanks




Sponsored Link
Ads by Google

Response Number 1
Name: goofman
Date: October 20, 2004 at 12:39:48 Pacific
Reply:

hello, sorry, im pretty handy with batch files, but to tell ya the truth, i dont pay attention to use all thet %1 stuff, except when i make a menu like '%choice%' but i know how to make a loop, im not sure if its what your looking for but here is a loob to tell the time and date...

echo off
title loop
cls
:up
echo %date% %time
cls
goto up

and that would update the time and date every split second...is this any help ?


0

Response Number 2
Name: goofman
Date: October 20, 2004 at 12:41:08 Pacific
Reply:

forgot about the other % in time


0

Response Number 3
Name: Mechanix2Go
Date: October 20, 2004 at 23:17:24 Pacific
Reply:

Hi Shrads,

If that's your real code, you have a couple obvious problems.

1. The path separator in DOS & windows is the SINGLE backslash.

So these won't help:

d:\\dir1
d://dir3//test1.txt

2. I guess you mean to use this as a comment

//command to be run

as in C or C++

It won't work in batch. In batch, a comment goes on a line by itself, preceeded by

::

or

rem [and at least one space]

examples:

::this is a comment
rem this is a comment
remthis is a mess
dir //this is also a mess

After you wring out those problems, post back.

HTH

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file FOR LOOP

Batch file for Outlook www.computing.net/answers/programming/batch-file-for-outlook/15439.html

Need help on Batch file for Shutdow www.computing.net/answers/programming/need-help-on-batch-file-for-shutdow/16424.html

Batch file drive loop www.computing.net/answers/programming/batch-file-drive-loop/18537.html