FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Help with Batch Files

   
Author Topic: Help with Batch Files
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Ok can anyone help me understand the FOR AND DO cmds for Batch files and how to pass parameters between batch fies? thanks.
IP: Logged | Report this post to a Moderator
Chanie
Member
Member # 9544

 - posted      Profile for Chanie   Email Chanie         Edit/Delete Post 
A parameter for a batch file is passed on the command line after a space. Like let's say you wanted to pass the parameter "hello" for a batch program called Blayne.bat. On the command line, you would type:
Blayne hello

In the batch file, you would reference the argument with %1. The second argument is %2, etc. Such as "echo %1."

I don't understand the first part of the question.

You'd probably be best off doing something like googling "DOS batch files."

Posts: 159 | Registered: Jun 2006  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
It would be helpful if you were to confirm that you are indeed working on DOS, or generally what operating system you are under.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Mike
Member
Member # 55

 - posted      Profile for Mike   Email Mike         Edit/Delete Post 
My advice? Install cygwin and use bash. [Wink]
Posts: 1810 | Registered: Jan 1999  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
DOS prompt.
IP: Logged | Report this post to a Moderator
Avin
Member
Member # 7751

 - posted      Profile for Avin           Edit/Delete Post 
Type
> for /?

at a prompt and it will spit out for you a help page that documents everything you need to know.


Here's an example of a for loop I made in a batch file I use at work:

for %%I in (%UPGROOT%\5100\*) do echo DELETEFILE "..\5100\%%~nxI"; >> %S5SCRIPT%

This will enumerate all the files in the directory specified by %UPGROOT%\5100\ (where %UPGROOT% is a variable defined elsewhere), and write a line to a file (specified by %S5SCRIPT%) of the form

DELETEFILE "..\5100\filename";

(note that the filename then will NOT include the path the file was found at)

Posts: 142 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
Note that you should almost never write batch files nowadays unless you have to. WMI and PowerShell are better alternatives.
Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2