Last active
February 2, 2018 16:43
-
-
Save JohnL4/4f819b1db6a1dc6e19ee0d3da18e9fba to your computer and use it in GitHub Desktop.
Set string environment variable (e.g., $env:JAVA_HOME) to most-recently-created subdirectory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So, we're not dependent on filename sort order ("9" > "10"). | |
if (Test-Path "c:/usr/local/Java") { | |
$env:JAVA_HOME = $(ls c:/usr/local/Java | sort CreationTime -desc | select -first 1 FullName).FullName | |
} | |
else { | |
Write-Warning "No Java" | |
} | |
# TODO: could probably use a list of directories to search (e.g., @("c:/usr/local/Java", "c:/Program Files/Java")). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment