×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Kill a file to the Recycled or Recycle Bin folder ?

Kill a file to the Recycled or Recycle Bin folder ?

Kill a file to the Recycled or Recycle Bin folder ?

(OP)
I have written a program that can delete the selected file in a Filelist control when the user presses the DEL key. But, I would like to send the file to the Recycled (W9x) or Recycle Bin (NT) folder so that it can be restored if the user changes their mind. The FileCopy command works well to copy a file to other folders but not to C:\Recycled. Is there a Win32 API or something else I'm not thinking of that can place files in the Recycled folder for later restoration?

RE: Kill a file to the Recycled or Recycle Bin folder ?

Try this in a .BAS module:

Option Explicit

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 String ' only used if FOF_SIMPLEPROGRESS
End Type

Public Const FO_DELETE = &H3
Public Const FOF_ALLOWUNDO = &H40

Declare Function SHFileOperation _
Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Function ShellDelete(FileName As String)
Dim I As Integer
Dim sFileNames As String
Dim SHFileOp As SHFILEOPSTRUCT

sFileNames = FileName & vbNullChar
With SHFileOp
.wFunc = FO_DELETE
.pFrom = sFileNames
.fFlags = FOF_ALLOWUNDO
End With

ShellDelete = SHFileOperation(SHFileOp)
End Function

Of course, this code has a dependence on the Windows 95-style shell, so it won't work on any version of NT prior to 4.0. I think Microsoft said that this might have changed under Windows 2000, but I don't know for sure.

You can also string together a series of files to be deleted, by separating them with vbNullChar's.

Chip H.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close