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 16,2020 at 13:58
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

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

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

should be

If ":\"=="%%Object:~1,3%%" (


thanks this will simplify a lot of things, and....

>brackets force environment variables to be expanded early.
i dont undersrtand the meaning of "variables to be expanded".
they dont't just grow up do they?
this could be the problem of a lot of my failed call-subrountines i have packed behind closets left there forever.

838 views      
Thread locked
 

Messages in this Thread

 
96,640 Postings in 12,231 Threads, 350 registered users, 62 users online (1 registered, 61 guests)
Index | Admin contact |   Forum Time: Apr 18, 2024 - 12:22 pm UTC  |  Hits:62,913,584  (8,008 Today )
RSS Feed