Quarksoft Blog

This is where we post useful information for everyone. Lots of it is technical, but some can be used by anyone.

Archive for October, 2007

Some more command line fun – sending email

After all the work I did with the dates in the environment variable I had a need to email the files I was working with.  Found a really GREAT command line utility that allows for sending email from a batch file.  It has nearly endless options and took about 2 minutes to setup and get working in our environment.  It’s called Blat and is available from this site.

If you want to learn a lot about sending email and can read C++ you can also download the full source code for Blat.

Getting date information into environment variables

If you have ever tried to script data downloads and log file manipulation you probably have run across the need to embed the date into a filename during a copy/move operation within a batch file.  I have never been able to find a built-in way to do this within Windows.  Here are a few lines that allows you to get the month, day and year into their respective environment variables.

If you add the following to your command/batch file:

@echo off
FOR /F "TOKENS=2* DELIMS= " %%A IN ('date/t') DO SET mdy=%%A
FOR /F "TOKENS=1* DELIMS=/" %%A IN ('echo %mdy%') DO SET month=%%A
FOR /F "TOKENS=2* DELIMS=/" %%A IN ('echo %mdy%') DO SET day=%%A
FOR /F "TOKENS=3* DELIMS=/" %%A IN ('echo %mdy%') DO SET year=%%A

You will then be able to use the following environment variables:

%month% to return the month
%day% to return the day of the month
%year% to return the 4 digit year.

If you need any assistance with this, feel free to comment below.