Read Mode

The FOR Command - Part I - An Introduction | Learn Batch Programming - Part III

How the FOR LOOP in cmd Works? Examples for cmd For Loop Multiple Commands? How to loop a command in cmd? Such kind of questions is annoying Batch Programmers from the Stone Age! And, There is no Genuine Resource on the Internet, which explains For Command better with examples and its parts. So, TheBATeam Decided to include this one in the Series of Learn Batch Programming.
Our greatest glory is not in never falling,
But in rising every time we fall.
The FOR Command - Part I - An Introduction | Learn Batch Programming - Part III
The FOR Command - Part I - An Introduction | Learn Batch Programming - Part III

The For Command - Part I - an Introduction!

So, Every one of Us has seen FOR Command's Usage in all the possible high-level Batch Codes. But, When I was a beginner - I always got stuck on that line of code, which has For Loop. Because I had no idea what For Command can do? And, as I was a beginner - I started looking for some resource to learn cmd commands tricks. but, All I got was the pieces of information. So, I learned from all those broken pieces.

What is For Command?

For Loop Help
Help Msg
If you'll look for the help from Windows traditional /? tool. then, You are going to be very disappointed. As, the help provided by Microsoft is not that much helpful. So, You can Understand FOR Command as a Command, which takes a Set (set of number, Set of alphabets, Set of names, Set of ....almost anything!) And, Applies some selected commands on the items in the set. Following Examples and the video Tutorial will help you a lot.
For %%A in (1 2 3 4 5) Do (Echo %%A)

What is a Set in For Loop in CMD?

A Set is nothing, but a group of Items kept together. Like, In the Following Example picture - The Set is numbers from 1 to 5. In this one Set of numbers - we have 5 numbers. You can put alphabets, filenames, folder names etc. And, For Loop will consider it as a Set. And, then you can apply actions on the set.

FOR LOOP Example

Topics Covered in 'Learn Batch Programming - Part III' - The FOR LOOP - I

The Tool for Mass Destruction - The FOR COMMAND
  • Simple Syntax of FOR COMMAND
  • PARTS of FOR COMMAND and Their Significance in OUTPUT
  • The POWER of FOR COMMAND in CMD/Windows
  • How You can Automate Some Tasks Combining a few commands with FOR LOOP in Windows
    • Auto-Creating Folders after specific seconds (combining with Timeout Command)
    • Auto Deleting Folders after specific seconds.

Video Demonstration

As, Always - a video is a great way to learn things. Because, it is full of examples and execution of Codes. Have a look at this short 10 min video and Understand the basic cmd commands. The Best thing about CMD and its commands is that - with new version of windows, You get new commands.

Reference Material PDF (to read)

If you want to learn more in-depth details about the FOR LOOP/COMMAND in cmd. Then, you must give a try to this small 20 Pages Book (PDF) that I've written to help everyone out. If you have any doubt or suggestion for me to add in this article. Just leave a comment below - And, I'll try to help you out as soon as possible. And, I'll see you soon with another informative article on TheBATeam.

No comments:

Powered by Blogger.