|
Удаление файла в корзину |
|
|
Если у вас в опциях корзины Windows не стоит галочка "Уничтожать файлы сразу после удаления", то данный пример удалит созданные вами файлы в корзину. Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4
Sub SendFileToRecycleBin(FileName As String, Optional Confirm As Boolean = True, Optional
Silent As Boolean = False)
Dim FileOp As SHFILEOPSTRUCT
With FileOp
.wFunc = FO_DELETE
.pFrom = FileName
.fFlags = FOF_ALLOWUNDO
If Not Confirm Then .fFlags = .fFlags + FOF_NOCONFIRMATION
If Silent Then .fFlags = .fFlags + FOF_SILENT
End With
SHFileOperation FileOp
End Sub
Private Sub Command1_Click()
SendFileToRecycleBin "C:\1.txt", False
SendFileToRecycleBin "C:\11.txt", True
End Sub
Private Sub Form_Load()
Dim FN As Integer
FN = FreeFile
Dim FName As String
FName = "C:\1.txt"
Open FName For Output As #FN
Print #FN, ""
Close #FN
FName = "C:\11.txt"
Open FName For Output As #FN
Print #FN, ""
Close #FN
End Sub
|
|
|
|
|
|
|