This could as well be called “the beginner’s guide to .bat“. First of all, it a good idea to download some tool to help us start right away. I personally have found the best solutions to be the Microsoft Visual Studio Code and Notepad ++. Both are free and both do just great. Although writing a script can be done in notepad as well, I prefer some highlighting of an advanced editor. I think that based on my experience, people tend to think about writing a .bat script this way: “Yeah I have some basic knowledge od the cmd, writing a script will be easy”. I believe this is a mistake, as scripts works a bit differenent and people used to write C/C++/Java … will be quite confused about variable storing, code syntax and for cycles especially.

My first for-cycle written in .bat file took me about 2 +Hours to finish. Although it can be copied from web, I rather think about the commands, untill I am pretty sure what it exactly does. And as I say,there is no Int, unsigned int, auto ,float or double, there is only a string and the for-cycle runs on strings in fact. These are mostly file names and paths. I have added this sample code I believe will be pretty useful for people trying to write some basic directory browsing script. At first the quotations “” seems to be useless, but you wouldn’t believe how usefull they are when you are about to work with a strange filename/filepath, that contains special characters such as space,% or !. Also remember that each commands should have only one space before and after the commands. Well almost,except for setting variables …. and maybe something else :) 


Share This