JSI Tip 6933. How do I determine the attributes of a file in a batch?

In tips 0494, 3579, and 3580, I parsed a file batch parameter.

The %~a1 syntax will return the attributes of file %1. If %1 was C:\Boot.ini, %~a1 would normally display -r-hs----.

I have scripted GetAttributes.bat to return a call directed environment variable with the attributes of %1, without the -.

The syntax for using GetAttributes.bat is:

Call GetAttributes.bat FileName Attributes

Where FileName is the fully qualified name of a file, and Attributes is the name of the variable you want set.

GetAttributes.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: Call GetAttributes FileName Attributes&goto :EOF
set %2=
if not exist %1 @echo File %1 not found.&goto :EOF
setlocal
set filename=%1
set attr=%~a1
set attr=%attr:-=%
endlocal&set %2=%attr%



Hide comments

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.
Publish