JSI Tip 3580. How can I set an environment variable to a dir-like output line?

Jerold Schulman

April 12, 2001

1 Min Read
ITPro Today logo in a gray background | ITPro Today

In tip 3579 and link, we parsed batch parameters.

Windows 2000 supports a special format, %~ftza1, which will expand the batch parameter (1) to a dir-like output line.

If you call a batch with a file name that is in the current directory, or with a fully qualified file name, the %~ftza1 syntax will yield a dir-like output line. If the file is not found, it will return the input or implied path. Examples:

The batch file contains:

set test=%~ftza1
@echo test=%test%

If the current folder is C:, a call testbatch filename.txt will set test to c:filename.txt if the file does not exist. If c:filename.txt exists, test would be set similar to:

--------- 12/07/99 08:00 50960 C:filename.txt.

If you call testbatch D:TEMPfilename.txt, test would be set similar to:

-rahs---- 04/12/01 09:32 19456 D:TEMPfilename.txt

You can determine if the file was found by including:

if "%test:~0,1%" EQU "-" goto found

NOTE: See the file attributes at -rahs----.


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like