I want to write a batch file and we want to use if-then-else and for loop statements, but I don't know it and its option.
Please can anyone help me?
I want to write a batch file and we want to use if-then-else and for loop statements, but I don't know it and its option.
Please can anyone help me?
Microsoft usually has good information on their website. Here's info on batch files.
If you are looking to do anything relatively complex, you might be better of using something more modern than batch files.
Since windows 2000 MS have provided the "Windows Scripting Host" which lets you script tasks using either VBScript (preferable if you have experience with VB6 or "Classic" ASP) or JScript (Microsoft's Javascript implementation). See MS's documentation for reference information, and there are many online tutorials. Of course some simple tasks that batch files are used for are more work in WSH (copying and moving files using the FileSystemObject takes a few more lines of code than simply "copy x y
" in a batch file, for instance), so a batch file may be the best tool for the job in hand even though the flow control options are very clunky.
There is also PowerShell, available for XP/2003 and above, which also has a far more expressive scripting featureset (though I've not got around to playing with PS myself, so I can't comment on how it compares to other options).
If you are familiar with unix-a-like systems you can transfer some of that knowledge by having something like bash
installed (I have cygwin installed on all by Windows boxes, and use bash and all the other common tools like rsync and the GNU text processing utilities through cygwin's ports).