Tag Archives: batch

Windows: How to Comment out a Line in a Batch File Tips, Tricks and Tutorials 27 JAN 2014

20091016-Windows-Command-PromptAs a reminder to myself so that I don’t have to Google it each and every time I need to work on a Windows Server (in other words, very seldom), there are three ways of adding comments into batch files (.bat) in Windows.

The first, most recognised way (standards-compliant, documented statement) is by making use of the REM statement. Any line in your batch file that starts with REM (which stands for REMark) is completely ignored by the batch interpreter.

Of course, because the way in which batch files are processed by COMMAND.COM and CMD.EXE, i.e. the batch file is read, the command is executed, and then the batch file is reread in order to execute the next command, rinse and repeat until the end of the file, REM statements do in essence slow down the execution of a batch file – though taking into account today’s processing power, this slowdown is negligible (unless of course your batch file is SUPER long!).

REM Comment - This bat-file moves all files

At this point it might be useful to remind yourself that by default the batch interpreter will print out each command before it is processed. Since REM commands don’t do anything, it’s safe to print them without any side effects. If however you want to avoid printing a command, including the REM statement, prefix it with @, or, to apply that setting throughout the program, run @echo off. (It’s echo off to avoid printing further commands; the @ is to avoid printing that command prior to the echo setting taking effect.)

The second way of commenting out a line in a batch file is by utilizing a clever trick that in essence has you converting your comment line into a label by prefixing it with a double colon (::). The first colon tells the batch interpreter that the following text is a label, while the second colon invalidates the label status but then forces the interpreter to still treat the line as a label anyway. This trick has the advantage of not slowing down the interpreter because it doesn’t have to stop to interpret the command statement like it has to for a REM statement – it simply jumps to the next line of the file without having to first reread the whole file again!

:: Comment - This bat-file moves all files

However, this trick does not allow you to start a comment mid line as labels always start at the first non-whitespace character in a command line. Also, code blocks are a pitfall for this trick as commands grouped by parentheses are interpreted as a single command line by the batch interpreter, which then obviously invalidates our ‘fake’ label as just mentioned above – your comment most likely won’t be sitting at the start of the concatenated command line!

Finally you can write multiple lines of comments (or comment blocks) by making use of the ability to jump over your lines of comment using the GOTO statement. In practice:

GOTO EndComment
Comment - This bat-file moves all files
Line 2 - Written by Craig
Line 3 - 2014-01-27

Note, it is probably a good idea to help others understand what is going on by using a descriptive GOTO label name.

And there you go, three different ways of adding comment lines into your .bat batch file.

Related Link: http://www.robvanderwoude.com/comments.php

Tech Tip: Retain your windows desktop environment on any device (PC/Mac/Linux/Android/iOS) by remote accessing your citrix xendesktop from CloudDesktopOnline at an unbelievable citrix xendesktop pricing. To enhance your experience with desktop in the cloud try out dedicated GPU hosting from Apps4Rent to fulfill your graphics requirements.

Ubuntu: Batch Resize Your Images using GIMP CodeUnit 04 JAN 2010

Digital Cameras these days take fantastically detailed and large photos, brilliant for printing and editing but not always that great if you want to simply pop them up on the web for everyone on FaceBook to gaggle over. So obviously a spot of resizing is required first, but who the heck would want to individually resize 600 photos of Aunt Nelly’s Wedding Reception, one photo at a time?

Now if you’re a diehard Ubuntu user, you’ll know that the first and foremost image editing package available to you is GIMP, and so today’s quick chunk of useful information revolves around batch resizing images using GIMP.

As great as GIMP is, it doesn’t feature native batch functionality and as such we find ourselves turning to the excellent David’s Batch Processor extension script which plainly put, does. To get it, the easiest thing to do is head over to your Synaptic Package Manager and do a search for gimp-plugin-registry. This neat little package bundles together a whole lot of useful GIMP plugins, including the one that we’re interested in, namely David’s Batch Processor. Mark for installation and apply.

Once installed, open up GIMP and access the Filters -> Batch -> Batch Process… menu option. This will launch David’s Batch Processor and from this point onwards it is pretty simple to get going. First, select all the files or the folder containing the files that you wish to process on the Input tab. Once selected, visit the various tabs to set whatever batch operation you want to apply to the images. Obviously the resize would be the number one tab visited in this instance! :)

Once your manipulation options have been set in, visit the output tab, makes sure you happy with where and how the processed files are going to be saved and once complete, hit the start button to launch the batch processor.

Couldn’t be simpler!

Related Link: http://members.ozemail.com.au/~hodsond/dbp.html