Solved

recycle bin

Posted on 1998-07-08
4
290 Views
Last Modified: 2010-05-03
i have a file list box and it is set to extended to select files i want to be able to delete all the selected files to the recycle bin if possable ive tried the kill filename but it only deletes one file and not all the selected files and it deletes them off the disk instead of moving them to the recycle bin woult also like to know how to delete a selected file by pressing the del button on the keyboard
0
Comment
Question by:p400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:p400
ID: 1465234
Edited text of question
0
 
LVL 2

Expert Comment

by:Jagar
ID: 1465235
instead of using the kill command copy the file to the recycle bin directory.
0
 
LVL 7

Accepted Solution

by:
tward earned 50 total points
ID: 1465236
Straight from the Microsoft Knowledge Base:

How To Delete a File into the Win95 Recycle Bin

Last reviewed: July 26, 1996
Article ID: Q154005

The information in this article applies to:

•Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SUMMARY

This article describes how to use the Visual Basic function called KILL to enable a user to delete a file from disk. Under Windows 95, there is an additional feature of deleting files into the Recycle bin, giving a user the ability to reclaim deleted files. The KILL function doesn't offer this to the Visual Basic Programmer, but the SHFileOperation Win32 API does. Below is a code sample showing how to use the API in Visual Basic.

MORE INFORMATION

1.Start a new project in Visual Basic. Form1 is created by default.

2.Place a Command button on Form1.

3.Add the following code to the Form1 code window:

Option Explicit

Private Type SHFILEOPSTRUCT
     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

   Private Declare Function SHFileOperation Lib "shell32.dll" Alias _
     "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
   Private Declare Function GetTempFileName Lib "kernel32" _
     Alias "GetTempFileNameA" (ByVal lpszPath As String, _
     ByVal lpPrefixString As String, ByVal wUnique As Long, _
     ByVal lpTempFileName As String) As Long

   Private Const FO_DELETE = &H3
   Private Const FOF_ALLOWUNDO = &H40

   Sub Command1_Click()
     Dim FileOperation As SHFILEOPSTRUCT
     Dim lReturn As Long
     Dim sTempFilename As String * 100
     Dim sSendMeToTheBin As String
     lReturn = GetTempFileName("c:\", "VB_", 0, sTempFilename)
     sSendMeToTheBin = Left(sTempFilename, InStr(sTempFilename, Chr$(0)))
     With FileOperation
        .wFunc = FO_DELETE
        .pFrom = sSendMeToTheBin
        .fFlags = FOF_ALLOWUNDO
     End With
     lReturn = SHFileOperation(FileOperation)
     MsgBox "View your Recycle Bin for files beginning with VB_"
   End Sub

4.Press the F5 key to run the project, and click the Command button. You will be prompted to confirm the deletion of the file. In your Recycle Bin, there will be a file with the prefix "VB_" that is the file created by the GetTempFileName Win32 API call.

REFERENCES

The Win32 SDK Helpfile refers to other SHFileOperation functionality.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1465237
I tried posting the same thing basically, but tward was quicker :-)

One thing I'd like to point out is that the example creates a temporary file so it can then delete it,  so don't get confused by the creation of the temporary file, it's just there for an example.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question