-
Mar 18th, 2003, 12:00 PM
#1
Thread Starter
Addicted Member
VB6 - Moving Files to the Recycle Bin
When a file is deleted in windows, it is not automatically erased. Instead, it is put into the recycle bin. Thus, an unwanted deletion can easily be undone. You can do this in your programs with these codes;
VB Code:
' Copy this code into a module
' You can add a module by right clicking in the project
' explorer of vb
Public Type SHFILEOPSTRUCT
hwnd As LongwFunc As
LongpFrom As StringpTo As Stringf
Flags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Public Declare Function SHFileOperation Lib _"shell32.dll" _ Alias "SHFileOperationA" (lpFileOp _As SHFILEOPSTRUCT) As Long
Public Const FO_DELETE = &H3
Public Const FOF_ALLOWUNDO = &H40
Public Function Move2RecycleBin(strfile as String)
'strfile is the full path of the file you want to put in the recycle bin
Dim SHop As SHFILEOPSTRUCT
With SHop
.wFunc = FO_DELETE
.pFrom = strFile
.fFlags = FOF_ALLOWUNDO
End With
SHFileOperation SHop
End Function
'Sample Usage
Private Sub Form1_Activate()
Move2RecycleBin("C:\PutMe.txt")
End Sub
'Code By : Rigie O. Acebedo
Last edited by ripple214; Mar 18th, 2003 at 12:04 PM.
[vbcode]
If SymptomsPersist Then Goto VBForum
[/vbcode]
This is our world now...the world of the electron and the switch, the beauty of the baud.We make use of a service already existing without paying for what could be dirt cheep if it wasn't run by profiteering gluttons, and you call us criminals. We explore...and you call us criminals. We exist without skin color, without nationality, without religious bias...and you call us criminals. You build atomic bombs, wage wars, murder, cheat, and lie to us and try to make us believe it is for our own good, yet we're the criminals. Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for. I am a hacker and this is my manifesto.You may stop this individual, but you can't stop us all...after all, we're all alike."
+++The Mentor+++
-
Jul 7th, 2008, 09:22 PM
#2
Re: VB6 - Moving Files to the Recycle Bin
You should check for the possibility of the user Canceling the dialog. You do that by looking at If FileOperation.fAnyOperationsAborted which will be True in that case.
-
Aug 10th, 2024, 10:34 AM
#3
Member
Re: VB6 - Moving Files to the Recycle Bin
For an update as of August, 2024 under Windows 10 the function provided still works perfectly.
It works with reasonable speed but not as quickly as the simple "NAME" command that I previously used when saving files that might be needed later or "accidentally" erased.
My present program is working with tens of thousands of files of wildly varying size and multiple format so speed is actually becoming significant factor and I'm employing a virtual disc for the first time since I used them (in "extended" memory) to store simple text screen images enabling effectively instant screen changes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|