Non-existant directories in System PATH variable


  1. Posts : 149
    Windows 7 Ultimate x64
       #1

    Non-existant directories in System PATH variable


    "echo %PATH%" gives me a list of 32 directories.
    12 of these don't exist on my system, for example: C:\Windows\System32\WindowsPowerShell\v1.0\

    Is there any reason to keep these directories in my System PATH variable?
    Is something likely to come along wanting to use one of these directories?
    Do the missing directories have any significant performance penalties?

    I only came across this when I wanted to add a new directory to the PATH, and was faced with editing a huge string in a tiny input area (inside "System" in the Administrator Tools). Perhaps there's an easier way to manipulate the PATH variable?
    Last edited by swiftie; 01 Feb 2015 at 13:36. Reason: Added last paragraph
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    Hi, Swiftie, again,

    The path you claim that does not exist on your system, should. C:\Windows\System32\WindowsPowerShell\v1.0 is where powershell.exe lives, and PowerShell exists on all versions and variants of Windows 7.

    Verify you have PowerShell by running it. Or attempt to call to it through the command prompt. E.g execute the command powershell -?. If you successfully start PowerShell using either method, type the following command at the command line, where powershell. This will return the path to the PowerShell interpreter (which should be "C:\Windows\System32\WindowsPowerShell\v1.0" exactly).


    swiftie said:
    Is there any reason to keep these directories in my System PATH variable
    Is something likely to come along wanting to use one of these directories?
    Do [] missing directories have any significant performance penalties?
    Yes, yes and yes.


    swiftie said:
    Perhaps there's an easier way to manipulate the PATH variable?
    If you are comfortable with using the command line, there is the SETX command which is used to set persistent environment variables. The following is an example of how one would go about appending a path to the PATH variable,
    Code:
    setx "PATH" "%PATH%;C:\my\path" /m
    But I highly recommend you do not use setx to make edits to existing environment variables. Things can wrong. Use setx to create new environment variables.


    Note 1: A popular way of viewing the contents of the PATH variable is to echo out the following variable,
    Code:
    %PATH:;=&echo.%
    Note 2: In the PATH variable, please do not add a semicolon after the last entry in the list of directory paths.
    Last edited by Pyprohly; 02 Feb 2015 at 16:00.
      My Computer


  3. Posts : 149
    Windows 7 Ultimate x64
    Thread Starter
       #3

    Turns out that the API that I use to verify the existence of a directory doesn't tolerate a trailing '\' character on a directory name.

    So, I have a bypass - remove trailing '\' characters before passing the directory name to the API. Directory C:\Windows\System32\WindowsPowerShell\v1.0 does exist on my system.

    But this just raises another question... Should the directory name in the PATH variable have the trailing '\' removed, or should the API (or my code) be more tolerant?

    I've come across a version of this quandary whilst configuring the Apache webserver. In places where you specify directory names, you have to include the trailing '\'. Or omit it, I forget which. Oh, you can also use '/' if you prefer.
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    Typically a path that includes a trailing backslash is considered incorrect. I'm not too sure why the PowerShell path entry in the PATH variable includes a trailing backslash by default.

    You should always stick to the path naming conventions, however, your API could indeed be more tolerant and understand paths that include a trailing backslash.

    Is there some "get unresolved path" or "normalise path" function you can incorperate in your API that will tidy up paths and trim any excess backslashes from them?
      My Computer


  5. Posts : 149
    Windows 7 Ultimate x64
    Thread Starter
       #5

    Pyprohly said:
    ... Is there some "get unresolved path" or "normalise path" function you can incorperate in your API that will tidy up paths and trim any excess backslashes from them?
    Having got a directory name into a variable ("dir" say) then strip(dir,'T','\') will strip off trailing backslashes.

    The language I use is REXX, developed by IBM, and I worked for IBM in its formative period onwards. The beta testers wanted a rich variety of text-handling functions, and we got them.

    I'll admit that my code sometimes stores directory paths with a trailing '\'. That way, if you're generating fully qualified filenames from this directory and the name of the file, you just concatenate the directory name and the file name, without having to worry about including the '\' in between. It seems more efficient this way, and coding this way must have saved my PC at least a millisecond of CPU time, over the decades...
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:45.
Find Us