ZTree.com  | ZEN  | About...  

 Index   Back

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

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

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

LIB-OS1.BAT has

CALL :%1 %*
EXIT /B

:GetObjectType
(@ECHO OFF
Setlocal EnableDelayedExpansion

Set ObjectType=
Set "Object=!%~2!"

If ":"=="!Object:~1,2!" (

Set ObjectType=Drive

)

Set Attributes=
for %%I in (!%2!) do Set Attributes=%%~aI
If "d"=="!Attributes:~0,1!" (

Set ObjectType=Directory

) Else (

Set ObjectType=File
)

)
(EndLocal
SET %3=%ObjectType%
)
EXIT /B

-------------------------------------------------

A-OS1.BAT has

@ECHO OFF
SetLocal

SET IN=%1

CALL "LIB-OS1.BAT" :GetObjectType IN ObjectType

ECHO %ObjectType%

PAUSE
---------------------------------------------------
run A-OS1.BAT c:
-------------------------------------------------

i dont know how to escape to endlocal to get DRIVE.
i have to make it to external sub.

213 views      
 

Messages in this Thread

 
95,114 Postings in 11,994 Threads, 350 registered users, 101 users online (1 registered, 100 guests)
Index | Admin contact |   Forum Time: Oct 31, 2020 - 12:42 am UTC  |  Hits:35,024,670  (1,241 Today )
RSS Feed