SpecialFolderLocation (Source)

Iniciado por cobein, 22 Abril 2008, 20:17 PM

0 Miembros y 1 Visitante están viendo este tema.

cobein

Hola, aca les dejo un snippet que muestra como obtener carpetas del sistema, no es nada nuevo pero este codigo esta rediucido y bastante optimizado.


Código (vb) [Seleccionar]
Option Explicit

Private Const CSIDL_SYSTEM As Long = &H25

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Private Declare Function PathAddBackslash Lib "shlwapi.dll" Alias "PathAddBackslashA" (ByVal pszPath As String) As Long

Private Function GetSpecialfolder(ByVal CSIDL As Long) As String
    Dim sPath   As String * 260
   
    If SHGetSpecialFolderLocation(0, CSIDL, CSIDL) = 0 Then
        If Not SHGetPathFromIDList(CSIDL, sPath) = 0 Then
            Call PathAddBackslash(sPath)
            GetSpecialfolder = Left$(sPath, lstrlen(sPath))
        End If
    End If
End Function

Private Sub Form_Load()
    Debug.Print GetSpecialfolder(CSIDL_SYSTEM)
End Sub

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.

seba123neo

si esta bueno,aca dejo algunas constantes de carpetas mas:

Private Const CSIDL_ADMINTOOLS As Long = &H30
Private Const CSIDL_ALTSTARTUP As Long = &H1D
Private Const CSIDL_APPDATA As Long = &H1A
Private Const CSIDL_BITBUCKET As Long = &HA
Private Const CSIDL_COMMON_ADMINTOOLS As Long = &H2F
Private Const CSIDL_COMMON_ALTSTARTUP As Long = &H1E
Private Const CSIDL_COMMON_APPDATA As Long = &H23
Private Const CSIDL_COMMON_DESKTOPDIRECTORY As Long = &H19
Private Const CSIDL_COMMON_DOCUMENTS As Long = &H2E
Private Const CSIDL_COMMON_FAVORITES As Long = &H1F
Private Const CSIDL_COMMON_PROGRAMS As Long = &H17
Private Const CSIDL_COMMON_STARTMENU As Long = &H16
Private Const CSIDL_COMMON_STARTUP As Long = &H18
Private Const CSIDL_COMMON_TEMPLATES As Long = &H2D
Private Const CSIDL_CONNECTIONS As Long = &H31
Private Const CSIDL_CONTROLS As Long = &H3
Private Const CSIDL_COOKIES As Long = &H21
Private Const CSIDL_DESKTOP As Long = &H0
Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10
Private Const CSIDL_DRIVES As Long = &H11
Private Const CSIDL_FAVORITES As Long = &H6
Private Const CSIDL_FLAG_DONT_VERIFY As Long = &H4000
Private Const CSIDL_FLAG_MASK As Long = &HFF00&
Private Const CSIDL_FLAG_PFTI_TRACKTARGET As Long = CSIDL_FLAG_DONT_VERIFY
Private Const CSIDL_FONTS As Long = &H14
Private Const CSIDL_INTERNET As Long = &H1
Private Const CSIDL_HISTORY As Long = &H22
Private Const CSIDL_INTERNET_CACHE As Long = &H20
Private Const CSIDL_LOCAL_APPDATA As Long = &H1C
Private Const CSIDL_MYPICTURES As Long = &H27
Private Const CSIDL_NETHOOD As Long = &H13
Private Const CSIDL_NETWORK As Long = &H12
Private Const CSIDL_PERSONAL As Long = &H5
Private Const CSIDL_PRINTERS As Long = &H4
Private Const CSIDL_PRINTHOOD As Long = &H1B
Private Const CSIDL_PROFILE As Long = &H28
Private Const CSIDL_PROGRAM_FILES As Long = &H26
Private Const CSIDL_PROGRAM_FILES_COMMON As Long = &H2B
Private Const CSIDL_PROGRAM_FILES_COMMONX86 As Long = &H2C
Private Const CSIDL_PROGRAM_FILESX86 As Long = &H2A
Private Const CSIDL_PROGRAMS As Long = &H2
Private Const CSIDL_RECENT As Long = &H8
Private Const CSIDL_SENDTO As Long = &H9
Private Const CSIDL_STARTMENU As Long = &HB
Private Const CSIDL_STARTUP As Long = &H7
Private Const CSIDL_SYSTEM As Long = &H25
Private Const CSIDL_SYSTEMX86 As Long = &H29
Private Const CSIDL_TEMPLATES As Long = &H15
Private Const CSIDL_WINDOWS As Long = &H24


aunque al ser un numero Long directamente le haces un for del 1 al 60 y te las lista igual sin usar constantes...

saludos.
La característica extraordinaria de las leyes de la física es que se aplican en todos lados, sea que tú elijas o no creer en ellas. Lo bueno de las ciencias es que siempre tienen la verdad, quieras creerla o no.

Neil deGrasse Tyson