'///APIs///
Declare Function SHGetPathFromIDList& Lib "shell32.dll" ( _
ByRef pidl As Long, ByVal pszPath As String)
Declare Function SHGetSpecialFolderLocation& Lib "shell32.dll" ( _
ByVal hwnd As Long, ByVal csidl As Long, ByRef ppidl As ITEMIDLIST)
Const CSIDL_PROGRAMS As Long = &H2 'The file system directory that contains the user's program groups, which are also file system directories.
Const CSIDL_WINDOWS As Long = &H18 'The Windows folder.
'/// Types ///
Type SHITEMID
cb As Long
abID As Byte
End Type
Type ITEMIDLIST
mkid As SHITEMID
End Type
Sub votreCode()
MsgBox ObtenirLettreDisque & "Nouveau_répertoire"
'MkDir ObtenirLettreDisque & "Nouveau_répertoire"
End Sub
Function ObtenirLettreDisque() As String
Dim A$
Dim B$
'--- On contrôle 2 dossiers spéciaux différents ---
A$ = PathSpecial(CSIDL_WINDOWS)
A$ = Mid(A$, 1, InStr(1, A$, "\"))
B$ = PathSpecial(CSIDL_PROGRAMS)
B$ = Mid(B$, 1, InStr(1, B$, "\"))
If A$ <> B$ Then
ObtenirLettreDisque = "ErreurLettreDisque "
Else
ObtenirLettreDisque = A$
End If
End Function
Function PathSpecial(SpecialFolder As Long) As String
Dim Retour&
Dim A$
Dim IDL As ITEMIDLIST
Retour& = SHGetSpecialFolderLocation(0, SpecialFolder, IDL)
If Retour& = 0 Then
A$ = Space(512)
Retour& = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal A$)
PathSpecial = Left(A$, InStr(A$, vbNullChar) - 1)
End If
End Function