0

I need to get the letter of the drive my form is running from. The reason why i need this, is because i'll be copying a text file (from the removable drive in which the form will be) to the computer. Is it even possible? If yes could someone help me with the code?

NOTE I'm using Visual Basic 6

KirChhOff
  • 21
  • 5

3 Answers3

1
Dim disk_letter As String
disk_letter = Left(CurDir$(), 1)

That was all.

KirChhOff
  • 21
  • 5
0

This should return you the drive letter that you are running the exe from.

Left$(App.Path, InStr(App.Path, ":"))
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
lardymonkey
  • 728
  • 1
  • 16
  • 34
0

I think this is the best approach considering the drive letter can have more than one letter.

Dim driveLetter As String
driveLetter = Left$(App.path, InStr(App.path, ":") - 1)
  • 1
    This is nearly the same as [@lardymonkey's answer](https://stackoverflow.com/a/27551241/3025856) from seven years ago, except that you strip the outer slash. I don't believe that is strictly necessary here? But, if it is, then I'd call out that change. Otherwise, in the future, it makes more sense to just upvote on the existing answer—and optionally leave a comment if you think it can be improved. (You don't have enough reputation to do either at the moment; but in the meanwhile you should be wary of leaving largely duplicate answers.) – Jeremy Caney Sep 24 '21 at 18:11