Skip navigation

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

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:\TEMP\filename.txt, test would be set similar to:

-rahs---- 04/12/01 09:32 19456 D:\TEMP\filename.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----.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.