Skip to content

Instantly share code, notes, and snippets.

@phwelo
Created April 13, 2016 20:05
Show Gist options
  • Save phwelo/2c91e9561044e5eec2d237c5e488eae1 to your computer and use it in GitHub Desktop.
Save phwelo/2c91e9561044e5eec2d237c5e488eae1 to your computer and use it in GitHub Desktop.
Ruby function to find first available single-letter drive letter on a windows system
def findADriveLetter()
reverseAlphabet = ["Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"]
reverseAlphabet.each { |letter|
if File.exist?("#{letter}:\\")
return letter
break
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment