Search Tools Links Login

GetFolderPath


Visual Basic 6, or VB Classic

I've seen requests for this in the mail lists to here it is. This uses the windows scripting runtime to get the path to the requested directory. For example, as you know, the windows directory can be C:Winnt , c:windows, etc. This code will retrieve the correct path to the directory.
'Currently written to get the Windows, System32, or Temp directory. Add others as you'd like.

Original Author: SteamboatWilly

Inputs

The type of folder to look for (Windows, Windows System, Temp)

Assumptions

No Error Handling. Make sure that you enter your own error handling methods.

Returns

The path of the directory requested

Side Effects

Requires the Windows Scripting Runtime. Standard dll for the Windows OS with IE 6 installed.

API Declarations

'Also requires a reference to the windows Scripting Runtime.

Code

Option Explicit
Public Enum FolderType
fldWindows = 0 'i.e. C:WINNT
fldWinSystem = 1 'i.e. C:WINNTSYSTEM32
fldWinTemp = 2 'i.e. C:Temp
End Enum
'=================================================
' Function Name: GetFolderPath
' Inputs: The Special Windows Folder to get
' the path from
' Returns: string containing the desired
' directory path
'
' References: Windows Scripting Runtime
'
' Method: objFileSystem.GetSpecialFolder(1)
' Where: 1 = System Folder (ie C:winntsystem32)
' 2 = Temporary Folder (ie c:winnt emp)
' 0 = Windows Folder (ie C:winnt)
'
'
'=================================================
Public Function GetFolderPath(FolderType As FolderType) As String
Dim objFileSystem As Object

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

Select Case FolderType
Case fldWindows 'The Windows Directory
GetFolderPath objFileSystem.GetSpecialFolder(0)
Case fldWinSystem 'The Windows System Directory
GetFolderPath = objFileSystem.GetSpecialFolder(1)
Case fldWinTemp 'Windows Temp Folder
GetFolderPath = objFileSystem.GetSpecialFolder(2)
End Select

Set objFileSystem = Nothing
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 124 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.