Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interogating 'System' for Drive Letter

Status
Not open for further replies.

lj50v

Programmer
Sep 21, 2008
6
AU
Is it possible, or is there a function which will look at the OS and tell you which Drive (be it Local C: or Network Z:) you are on.
I have had a look through the Help! file but the only options I could find related to being able to isolate or establish the user drive and path, when you supplied a full pathname to a file eg. Z:\cms\data\importfiles.
 
I borrowed this code from the help file, which correctly identifies the drive and path of a specific file, where the (drvpath) parameter is passed to the module from a previous module where I had to specify
drvpath=Z:\data\cms\importfiles
What I would like to me able to do is have the system check if the programme is running from the network drive or the C: drive as the files it needs are in different locations
Is there a function or command that will check where the application lives and if so can it report back where it was started from to give me the drive letter
Sub ShowDriveLetter(drvPath)
Dim fs, dr
On Error GoTo SDLError
Set fs = CreateObject("Scripting.FileSystemObject")
Set dr = fs.GetDrive(fs.GetDriveName(drvPath))
Drive = dr
Exit Sub
SDLError:
Drive = "Z:"
End Sub
 
I'm not aware of any generic method, but both Word and Excel, certainly, and other Office apps, probably, provide the path in [blue][tt]Application.Path[/tt][/blue]. If you feed that into your routine you should get your answer.

I'm not sure, however, about the design you are proposing. User data should not normally be tied to the application in this way.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Not quite sure if it's what you need but;


Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
'string for drive must have trailing \ as in 'C:\'
' GetDriveType return values
Public Const DRIVE_REMOVABLE = 2
Public Const DRIVE_FIXED = 3
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_CDROM = 5
Public Const DRIVE_RAMDISK = 6
 
I have to agree with Tony. It seems odd.

"Is there a function or command that will check where the application lives and if so can it report back where it was started from to give me the drive letter"

Applications do not "live" anywhere, except in memory when they are executing. Files "live" in specific locations, yes.

I have to wonder about a situation where the executable of an application be either on a network drive , or a local drive:

"What I would like to me able to do is have the system check if the programme is running from the network drive or the C: drive as the files it needs are in different locations"

AND, that you need to know which. Where data files are loaded from (or saved to), yes, I can see that, but the executable? GetDriveType does not check for where an executable (now in memory one would assume) was executed from.

However, on the other hand, for Office apps, as Tony mentions, you can indeed get the drive the executable was executed from, with Application.Path.

So, yes, you can find out if Word - say - was executed/started from a network drive, or a local drive.

BTW: should your Sub ShowDriveLetter(drvPath) actually be a Function, returning the value of Drive? Or is Drive a Public variable?
Code:
    Drive = "Z:"
As it looks there, while Drive is given a value (either dr or "Z:"), it does not seem to go anywhere.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 



Be careful. There's a difference between Application.Path and FileObject.Path, as in CurrentProject.Path, ThisWorkbook.Path or ThisDocument.Path.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
True. Noted. While the OP states:

" if the programme is running "

which, to me, means the Application...yes, there may (possibly) be some need to be careful not to confuse data items (ThisDocument, CurrentProject, ThisWorkbook, etc.), with the Application.

Still seems a bit odd to me.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top