Wednesday, June 5, 2013

Poor Batch Scripts

I was whipping up some Batch scripts to rename .eml files for me so that the names included the date, subject, to and from fields to make it easier to organize and find my archived emails.
I have long used bat/cmd scripts to do stuff like this but this little project took me a full day with many breaks to relieve the frustration.
Knowing Steve Wood who built the cmd batch processor is cool but it still never helped me figure out this problem:

The variables in batch scripts can use a syntax which allows some string substitutions like:

%foovar:x=y%  which returns the value of the variable with all x strings replaced by y.
Its nice for simple cases but I found it impossible to substitute out * characters.
This is because doing:

%foovar:*=-% is specially interpreted to mean all of the variable contents up to whatever comes after the *.

I tried %foovar:^*=-%%foovar:"*"=-% and even %foovar:**=-% with no luck.