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 22,2020 at 21:40
In Response to: [Help!] batch - how to find if it is a Drive or Dir or File (Ryan)

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


If you need the environment variables to be visible from the caller, you cannot use SetLocal, even to set EnableDelayedExpansion.

I do this sometimes, there will be an IOPS impact, but it works
----------
>%temp%\~LateExp.cmd Echo Set "Variable=%%CallerVar%%"
Call %temp%\~LateExp.cmd
Echo CallerVar=%Variable%
----------

You seem to insist on wanting to add extra unnecessary brackets, and then you complain of the consequences.
In your LIB-OS1.BAT example above, if you removed the extra brackets, the beginning one before the "@echo off" (also why put the "@echo off" contruct mid script?), you wouldn't need EnableDelayedExpansion, and would save yourself a load of pain.

In A-OS1.BAT, why are you doing this?
CALL "LIB-OS1.BAT" :GetObjectType IN ObjectType
and not
CALL "LIB-OS1.BAT" :GetObjectType "%~1" ObjectType
Then you wouldn't need delayed expansion, more causing yourself pain.

Reading that code, you have understood the you can execute variables point "CALL :%1 %*", but have some more to learn.


Programming in CMD is an exercise in pain, I use it mostly for quick and dirty, but sometimes I use it for the challenge, my film tagging script at home is ~3000 lines of complicated code, and one of my at work scripts is ~5000 lines (but actually a lot simpler), but I understand (I think most of) the limitations of CMD scripting, and how to handle a lot of them.

Maybe you should switch to powershell, or some other scripting language.

Ben

213 views      
 

Messages in this Thread

 
95,114 Postings in 11,994 Threads, 350 registered users, 94 users online (1 registered, 93 guests)
Index | Admin contact |   Forum Time: Oct 31, 2020 - 12:37 am UTC  |  Hits:35,024,546  (1,117 Today )
RSS Feed