Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: CleanPath (updated)

by tye (Cardinal)
on Jan 20, 2007 at 08:06 UTC ( #595648=note: print w/ replies, xml ) Need Help??


in reply to Re: CleanPath
in thread CleanPath

First off why does this only occur with %SystemRoo­t%

Other environment variables can be put in path components and CleanPath will handle them just fine. What it does special with %SystemRoot% is that if you put a directory in your $ENV{PATH} that is a subdirectory of %SystemRoot% without saying "%SystemRoot%", then CleanPath changes it to use %SystemRoot%. So "CleanPath C:\Windows\system32\trojans" will actually put "%SystemRoot%\trojans" into your path.

This feature was mostly added because the big motivation for writing this script was that a coworker had written a script to flush $ENV{PATH} changes into the registry and done a bad job of it, not realizing that $ENV{PATH} doesn't match what gets put in the registry for several reasons (notably user-specific path components and expansion of %SystemRoot%) so I wanted to clean this mess up easily (quite a few system had been corrupted by this before anyone noticed). If you use %SystemRoot%, then those entries in your $ENV{PATH} continue to work even if the drive letter for that partition changes on your when you reboot (and I was working in situations where this wasn't that uncommon of a situation); that's why those entries are done that way.

I wasn't too worried about the bug you pointed out because just running CleanPath twice takes care of it. I didn't include your fix at first because I needed to look over how I was using %GoodPath to convince myself that there were no problems with that fix. I just now incorporated your fix (slightly differently) as I was making some other minor updates. Thanks!

- tye        


Comment on Re^2: CleanPath (updated)
Re^3: CleanPath (updated)
by matze77 (Friar) on Nov 18, 2009 at 13:28 UTC

    If you copy the code be sure not to miss the last "h" its on a newline +h ...:  my $path= join ";", map { ExpandEnv($_) || () } @UserPath, @SysPat i think the last should read @SysPath? Thanks MH

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://595648]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-21 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (173 votes), past polls