January 2005 - Posts

Get Directory Path of an executing Batch file

Most people probably know that can use the variable %0 in a batch file to get the name of the executing batch file. However if you use that in conjunction with some batch parameter modifiers you can easily split that into a drive, directory or filename. Therefore to get the location of an executing batch file from within that batch file you can use the variable %~dp0. Where d is the drive, p is the path and 0 is of course the name of the executing batch file.

This comes in real handy for me because I have some batch files on network drives that do some simple installs. Since the install files are usually in the same directory as batch file I can use %~dp0 as their path. Now when I double click on a batch file in windows explorer whether the drive is mapped or a UNC path the batch file has the correct path to the files.

If the drive is mapped this is not really necessary because the working directory is set to the directory that the batch file is in. However if you access this directory via a UNC path this is not the case. So by using %~dp0 you can get the correct directory path, even for UNC paths. Before I took the time to figure this out I always had to map the network drive to run the batch file, but no longer.

This was inspired by comments on Raymond's Capturing the current directory from a batch file post. On commenter suggested changing to the directory by using "cd /d %0\.." this of course doesn't work for UNC paths, so I just used the path instead. On another note instead of using "cd /d %0\.." to change the directory you can use "cd /d %~dp0" instead.

Enjoy!

Over 100,000 hits

Wow I just looked at my hit counter on my blog this weekend and I have just passed 100,000 hits. This is since May 2003. That is pretty cool.

The majority of my hits are from search engines. It is good to see that I at least help some people in their quest of finding answers. As stated in my blogging philosophy that is my primary reason for blogging.

Posted by puzzlehacker | with no comments

Outlook Blank Email Message Filter/Rule

The other day I posted about Empty Email Messages. I haven't figured out exactly why it happens yet but one of the commenters suggests it maybe due to a corrupt header. I think that maybe true but I don't know what to do to fix it.

Also there is not straight forward way to setup a rule to filter these messages. However after reading this newsgroup post, I did figure out how to setup a rule in Outlook 2003 to filter these empty emails.

The following tells how to create a Rule for Outlook 2003 that filters email messages with blank subjects and bodies.

  1. Create a blank rule for when a messages arrives
  2. Don't select any condition. (Note it may ask if you are sure if you want it to apply to every message received, say yes)
  3. Select the action appropriate for you, i.e. permanently delete it or in my case I just move it into another folder because I'm still trying to figure out a pattern.
  4. Select the exception "except if the subject or body contains specified words". Then for the specified words enter 'a', 'b', 'c', ...'z','0'..'9' (i.e. all the letters and numbers).
  5. Then give it a name and click finish (you probably should move this rule to the bottom so that other rules can do there work first)

What this rule does is take the action given on any message that doesn't contain a letter or number in the subject or body.

This rule feels like such a hack but I couldn't figure out any better way. Does anyone know of a better method?

Well I hope this helps someone else at least filter this annoyance.

Empty Email Messages

Lately I have been noticing an increase of completely blank email messages in my inbox. I get anywhere from 1-5 empty emails a day. The messages have nothing but a relatively small truncated internet header. Some of the internet headers are truncated in the middle of a header message. My guess is they are spam that gets stripped by some mail server but I really don't know. I have started keeping them in separate folder to see if I can maybe figure out a pattern.

Does anyone else have this problem?

Does anyone know why this happens?

Does anyone have any ideas to fix this problem?

Nerd Score of 83

I am nerdier than 83% of all people. Are you nerdier? Click here to find out!

Well I'm a big nerd but not as big as Scott Hanselman ;)

I'm back

It has been a long christmas break. I have been from Blacksburg to DC to Cincinnati to Detroit back to DC and now finally back to Blacksburg. My wife just graduated in Dec and moved to DC to start her new job. I stayed with her until my last semester at Virginia Tech started which was today.

I have been writing my MS Thesis pretty much non-stop for the last two weeks. My goal is to finish the writing by March 1st and then defend it April 1st. I think I'm on track to accomplish that but only time will tell. I have one class and a TA assignment that will feel like taking another class. So I'm two classes, a Thesis and about 4 months away from MS degree in Computer Science. Then of course I move even further away from my wife to Redmond to start my new job at MS. Hopefully she can get a transfer around that same time.

Well that is my excuse for not blogging much lately and I'm sticking to it. I really want to post some stuff from my thesis but I want to get it all written first and have my advisor look over. Once that happens and of course when I have time (which may not be until after I graduate) I plan on posting about it. Right now all I will say is that it deals with a design-by-contract approach in .NET.

More Posts