Option Explicit
'=======================================================
'CONSTANTES
'=======================================================
Private Const FO_DELETE As Long = &H3
Private Const FOF_ALLOWUNDO As Long = &H40
Private Const FO_COPY As Long = &H2&
Private Const FO_MOVE As Long = &H1&
Private Const FOF_SIMPLEPROGRESS As Long = &H100&
'=======================================================
'TYPE
'=======================================================
Private Type Fichier 'utilisé pour envoyer vers la corbeille
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
'=======================================================
'API
'=======================================================
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As Fichier) As Long
'=======================================================
'copie un fichier/dossier
'=======================================================
Public Function CopyFileOrFolder(ByVal sFileOrFolder As String, _
ByVal sDestination As String) As Long
Dim sFileToCopy As Fichier
'définit l'objet Fichier
With sFileToCopy
.wFunc = FO_COPY
.pFrom = sFileOrFolder
.pTo = sDestination
.fFlags = FOF_ALLOWUNDO And FOF_SIMPLEPROGRESS
End With
'procède à la copie
CopyFileOrFolder = SHFileOperation(sFileToCopy)
End Function
'=======================================================
'déplace vers la corbeille un fichier/dossier
'=======================================================
Public Function MoveToTrash(ByVal sFileOrFolder As String) As Long
Dim sFileToDelete As Fichier
'définit l'objet Fichier
With sFileToDelete
.wFunc = FO_DELETE
.pFrom = sFileOrFolder
.fFlags = FOF_ALLOWUNDO
End With
'procède à la suppression
MoveToTrash = SHFileOperation(sFileToDelete)
End Function
'=======================================================
'déplace un fichier ou un dossier
'=======================================================
Public Function MoveFileOrFolder(ByVal sFileOrFolder As String, _
ByVal sDestination As String) As Long
Dim sFileToMove As Fichier
'définit l'objet Fichier
With sFileToMove
.wFunc = FO_MOVE
.pFrom = sFileOrFolder
.pTo = sDestination
.fFlags = FOF_ALLOWUNDO And FOF_SIMPLEPROGRESS
End With
'procède au déplacement
MoveFileOrFolder = SHFileOperation(sFileToMove)
End Function
Le 19/04/2007 par violent_ken : Modifié le nom des variables
Seul les admins et l'auteur du code lui même peuvent modifier ce code.