Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Batch file FOR LOOP

Original Message
Name: shrads
Date: October 20, 2004 at 07:14:30 Pacific
Subject: Batch file FOR LOOP
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



Report Offensive Message For Removal


Response Number 1
Name: goofman
Date: October 20, 2004 at 12:39:48 Pacific
Subject: Batch file FOR LOOP
Reply: (edit)
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 ?


Report Offensive Follow Up For Removal

Response Number 2
Name: goofman
Date: October 20, 2004 at 12:41:08 Pacific
Subject: Batch file FOR LOOP
Reply: (edit)
forgot about the other % in time

Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: October 20, 2004 at 23:17:24 Pacific
Subject: Batch file FOR LOOP
Reply: (edit)
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


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file FOR LOOP

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




CPU and Graphics Upgrade Questions

VIRUS ALERT in Taskbar, HELP!

DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC