1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
Option Explicit
Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
' Enumération des dossiers spéciaux
Public Enum SpecialFoldersConstants
CSIDL_INTERNET_CACHE = &H20
End Enum
' Type
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
' Constantes
Public Const MAX_PATH = 260
Public Function GetSpecialFolder(SpecialFolder As SpecialFoldersConstants) As String
' Les variables
Dim RC As Long
Dim IDL As ITEMIDLIST
Dim sPath As String
' Récupère le dossier spécial
RC = SHGetSpecialFolderLocation(100, SpecialFolder, IDL)
If RC = 0 Then
' Crée un tampon
sPath = Space$(MAX_PATH)
' Récupère le path à partir de l'IDList
SHGetPathFromIDList ByVal IDL.mkid.cb, ByVal sPath
' Supprime les chr$(0) inutiles
sPath = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
'If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
Else
sPath = ""
End If
GetSpecialFolder = sPath
End Function
Public Sub chemin(inp, str)
Dim doss As Object
Set doss = CreateObject("scripting.filesystemobject")
Dim dossier, elem As Variant
Set dossier = doss.getfolder(inp)
On Error Resume Next
doss.deletefile inp & "\" & str, True
Err.Clear
For Each elem In dossier.subfolders
chemin elem.Path, str
Next
End Sub |