Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

another dirty trick for windows batch file

I shared in another earlier post a dirty tick to change directory to where the Batch File is located; this is useful when you want to run your batch file from any directory prompt;

C:\xxxx\yyy\anything\myscript.bat

The trick is one single line:

cd /d %0\..



However, this has some limitations.

It is more often than not when you release your batch file in a network shared directory, and your end user want to run directly from there (i.e. without copying to local disk); if the drive is not mapped to the local system, you will be caught in surprise when running the above line.


The error is "CMD does not support UNC paths as current directories";


The hack is simple -- another magic line:


pushd %~dp0



This post first appeared on Always Remember, You Are At Most Yourself; And, Yo, please read the originial post: here

Share the post

another dirty trick for windows batch file

×

Subscribe to Always Remember, You Are At Most Yourself; And, Yo

Get updates delivered right to your inbox!

Thank you for your subscription

×