You can do what with environment variables?

Sunday, September 24th, 2006 at 07:02pm

Fairly regularly I create a folder of the current date to aid in sorting out files I have downloaded or similar. I finally got tired of having to manually type the date in so I decided to have a look to see if there were any existing mechanisms, preferably tied in to the context menu for a folder under windows as I already have a number of scripts hooked in there.

Fairly quickly I found one solution that I was almost about to dismiss entirely as it required altering how windows formatted dates. Fortunately I had a look at some of the responses and found something both useful and disturbing about environment variables under windows:

  • A colon and a tilde following the variable name (inside the percent characters) lets you specify a range of characters to extract from the value of the variable: eg %DATE:~10,4% pulls out four characters starting from character ten; and
  • A colon and an equals sign (inside the percent characters as before) allows a substitution to be specified. eg %DATE:/=-% replaces any slashes with dashes.

The good thing about this is that it allows me to create a one liner that extracts certain parts of the date and reassembles them in the format I prefer. What is bad is that I have never seen this usage before and I cannot find any documentation about this ‘feature’.

Tagged with: