GetFolderPath
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.
AI
एआई सारांश: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
सोर्स कोड
Option Explicit
Public Enum FolderType
fldWindows = 0 'i.e. C:\WINNT\
fldWinSystem = 1 'i.e. C:\WINNT\SYSTEM32
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:\winnt\system32)
' 2 = Temporary Folder (ie c:\winnt\temp)
' 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
मूल टिप्पणियाँ (3)
Wayback Machine से पुनर्प्राप्त