Friday, March 28, 2008, 01:23 PM - Tips and Tricks
This week I have been trying to automate my Windows build. I have never done any automation on Window ever before. It was always on Unix with batch files and Perl. For a while I had mixed feelings about installing Perl on Windows and moving forward, but nevertheless I took the path of writing it all in BATCH script. If Perl is easier then Bash, then Batch scripting is way too difficult and slow – may be its just me.
While doing so, there was a time when I wanted to know my current directory and I was stuck trying to find out what is the windows command to get the current directory. I was a bit ashamed to ask Google about this. I tried PWD and CWD but na. I asked a few guys around me. Unfortunately they could not guess beyond PWD and CWD - which made me feel less ashamed of myself.
At last, I had to Google it and guess what I found. Its was the first DOS command I ever learned in my computer class way back in 1994. The great command is
CD
And if you are scripting you will find it in the environmental variable called CD, i.e. %CD%. How could I ever forget this? In Unix CD would always mean going back to your home directory, but that’s the different story and not an excuse for forgetting.While reading the doc. for the CD command, I found a few not-so-well-known features of the CD command and thought I will list them here for the entertainment of my readers.
1. If you are in C drive and you want to go to D:\mydir then we generally do
D:
cd mydir.
Well, you can directly say
CD /D D:\mydir.
The /D flag causes a drive change. I wonder why did they every keep this flag in the first place. Even if it has historic reasons, they should get rid of it now.
2. While mentioning an absolute path reference you don’t need to give the drive letter. Just start with “\”.
CD C:\mydir\somediris same as
CD \mydir\somedir
3. CD does not treat spaces as delimiters, so it is possible to CD into a sub folder name that contains a space without surrounding the name with quotes. If you have two sub dirs, one called Shuva and the other called Shuva Brata, then the command CD Shuva Brata would take you to Shuva Brata.
But the command MKDIR Shuva Brata would create two directories, one called Shuva and the other called Brata. The command rmdir Shuva Brata would delete both Shuva and Brata. Its just CD which is inconsistent(or call it special or call it confusing)
In Linux if you type cd – you go to the previous(not parent) directory. Example:
SHUVA:build 30] pwd
/home/build
SHUVA:build 31] cd /var/lib/
SHUVA:lib 32] pwd
/var/lib
SHUVA:lib 33] cd -
/home/build
SHUVA:build 34] pwd
/home/build
SHUVA:build 35]
The way to do this in Windows is:
c:\Program Files> PUSHD c:\utils
c:\utils>
c:\utils> POPD
c:\Program Files>
If somebody tell you that the command CD displays information about your CD drive, what would you say?
Happy CDing.//




( 3 / 43 )




Calendar




