http://qs321.pair.com?node_id=11144102


in reply to Cleaning %PATH% with WinBatch

I don't think this addresses your issue but seems generally relevant and maybe useful to know.

Substrings can be removed using the idiom below.

set PATH=%PATH:C:\perls\strawberry-perl-5.32.1.1-64bit-portable\perl\b +in;=%

A looped example and some gotchas are in this SO post.

Replies are listed 'Best First'.
Re^2: Cleaning %PATH% with WinBatch
by LanX (Saint) on May 22, 2022 at 22:48 UTC
    Thanks, I knew that construct and that SO thread already.

    Actually that's exactly how I inserted the "DISABLED" part, see demo here.

    Problem is that, like already explained, I would need to know all possible entries beforehand instead of being able to exclude anything following C:\perls\...

    I also looked into batch solutions to split on ; and loop over it. But that's not trivial because, believe it or not, a ";" could be part of a filename° and appending to a variable in a loop is not trivial in WinB*tch language... 🤦

    In short: batch is really a horrible language for a perverted file-system invented by a distorted sadist. ˛

    I'm thinking now it's a good bargain between mental sanity, maintainability and performance to use a Perl one-liner returning the cleaned path. But only called for that edge case, i.e. if batch detects C:\perls in the path.

    (I could also use PowerShell, but why adding one more technology at that place?)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) tho, I could ignore this problem as long as the paths of my Perl installations are clean, which goes without saying.

    ˛) I have to apologize that was too harsh.

    It's rather a mix of the worst parts of bash and zsh, with the source google translated to Chinese and back to English but via Khoisan, while purging all documentation during compilation with random settings.