Blog 1

Random Talk on Random Thoughts

Something About Win* Batch Files

| Comments |

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 M$ 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.

1
2
@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 M$ Win* is the same as $* in *nix.1


  1. How can I output all of a batch file’s arguments? by John Savill in Windows IT Pro. 

Comments