ZTree.com  | ZEN  | About...  

 Index   Back

[Help!] batch - how to find if it is a Drive or Dir or File   [Help!]

By: Ben Kent       
Date: May 16,2020 at 07:02
In Response to: [Help!] batch - how to find if it is a Drive or Dir or File (Ryan)

You added extra brackets, which broke the code, here it is with them REMed out.
In CMD, brackets force environment variables to be expanded early.

SetLocal
Call :GetObjectType %1

echo ObjectType=%%ObjectType%%

pause
goto :eof
REM -------------------------------------------
:GetObjectType
REM (
Set ObjectType=
Set "Object=%%~1"
If ":"=="%%Object:~1,2%%" (
Set ObjectType=Drive
goto :eof
)

Set Attributes=
for %%%%I in (%%1) do Set Attributes=%%%%~aI
If "d"=="%%Attributes:~0,1%%" (
Set ObjectType=Directory
) Else (
Set ObjectType=File
)
goto :eof
REM )
REM EXIT /B

95 views      
 

Messages in this Thread

 
94,977 Postings in 11,970 Threads, 349 registered users, 42 users online (1 registered, 41 guests)
Index | Admin contact |   Forum Time: May 30, 2020 - 11:01 am EDT  |  Hits:31,267,277  (3,802 Today )
RSS Feed