Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill a file to the Recycled or Recycle Bin folder ? 1

Status
Not open for further replies.

BruceHesher

Programmer
Jul 7, 1999
50
0
0
US
Visit site
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?
 
Try this in a .BAS module:<br>
<br>
Option Explicit<br>
<br>
Type SHFILEOPSTRUCT<br>
hwnd As Long<br>
wFunc As Long<br>
pFrom As String<br>
pTo As String<br>
fFlags As Integer<br>
fAnyOperationsAborted As Long<br>
hNameMappings As Long<br>
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS<br>
End Type<br>
<br>
Public Const FO_DELETE = &H3<br>
Public Const FOF_ALLOWUNDO = &H40<br>
<br>
Declare Function SHFileOperation _<br>
Lib "shell32.dll" _<br>
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long<br>
<br>
Public Function ShellDelete(FileName As String)<br>
Dim I As Integer<br>
Dim sFileNames As String<br>
Dim SHFileOp As SHFILEOPSTRUCT<br>
<br>
sFileNames = FileName & vbNullChar<br>
With SHFileOp<br>
.wFunc = FO_DELETE<br>
.pFrom = sFileNames<br>
.fFlags = FOF_ALLOWUNDO<br>
End With<br>
<br>
ShellDelete = SHFileOperation(SHFileOp)<br>
End Function<br>
<br>
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.<br>
<br>
You can also string together a series of files to be deleted, by separating them with vbNullChar's.<br>
<br>
Chip H.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top