2013-12-11

Something about Win* batch files

Get drive letter

If you run portable devices from a USB stick, sometimes you need to refer to other files that is in the same USB drive. Their relative position is stable, but the drive letter is not. Thus, referring to those files by absolute path doesn't work, unless you do the tedious modifications every time.
Method 1: set var=%cd:~0,3%
Method 2: set var=%~d0 (preferred) Use variable: %var%

Alias on Win*

If you're familiar with *nix and use M$-DOS, you may unconsciously type the ls command in DOS; or if you have a portable version of a software and you need to launch it by command, you will discover the difference between the name of the programs---one has portable at the end while the other one doesn't.
Copy and paste the following lines of code into any text editor.
@ECHO OFF
[command] %*
Save the whole file as [alias].bat and put the file under any folder found on PATH environment variable.
Run [alias] in the command prompt to see the effect.
Note: %* in Win* is the same as $* in *nix. [1]

Reference:
[1]: How can I output all of a batch file's arguments?

No comments:

Post a Comment