pondělí 8. června 2015

VBScript to check PATH environment variable

This simple script checks if all parts of the PATH variable are valid, i.e. all folders exists. Nonexistent folders, especially on network, can reduce computer performance.

set shell = WScript.CreateObject("WScript.Shell")

pathVarString = shell.ExpandEnvironmentStrings("%PATH%")
pathArray = Split(pathVarString, ";")

Set fso = CreateObject("Scripting.FileSystemObject")

for each path in pathArray
    If (fso.FolderExists(path)) Then
       msg = "Exists"
    Else
       msg = "*** Does NOT exists"
    End If
    WScript.Echo msg & " " & path
next


You can run it on command line like:

cscript check_path_for_nonexisting_directories.vbs

or create batch file to run it, e.g.:

@echo off
cscript check_path_for_nonexisting_directories.vbs
pause