Skip navigation

JSI Tip 8381. How can I determine if a NTFS file system object is a file or a folder?


I have scripted ForD.bat to determine if a NTFS file system object is a file or a folder.

ForD.bat uses the %~a1 syntax. If the first character of the attribute is a d, the object is a folder.

The syntax for using ForD.bat is:

\[call\] ForD FullyQualifiedFileSystemObject FDN

Where FullyQualifiedFileSystemObject is the fully qualified file or folder name, and FDN is a call directed environment variable that will contain:

Object is  Value
   File      F
   Directory               D
   Not Found      N

ForD.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: ForD FullyQualifiedFileName ForD&goto :EOF
if not exist %1 @echo ForD - %1 NOT found.&set %2=N&goto :EOF
setlocal
set FD=F
for /f "Tokens=*" %%a in ('@echo %~a1') do (
 set attr=%%a
)
if /i "%attr:~0,1%" EQU "d" set FD=D
endlocal&set %2=%FD%



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