Hello to all
simply when i delete a file and the file is goto recycle bin after deleted.
when we use ( Kill ) command then my file delete direct and cannot goto recycle bin
please help

See if this helps :

Private Sub Recycle2(ByVal FQFileOrFolder As String)
    'Late bound.
    Dim Delim As Integer
    Dim FItem As Object
    Const ssfBITBUCKET = 10
    
    Delim = InStrRev(FQFileOrFolder, "\")
    With CreateObject("Shell.Application")
        For Each FItem In .NameSpace(Left$(FQFileOrFolder, Delim - 1)).Items
            If Not FItem.IsLink Then
                If UCase$(FItem.Name) = UCase$(Mid$(FQFileOrFolder, Delim + 1)) Then
                    .NameSpace(ssfBITBUCKET).MoveHere FItem
                    Exit Sub
                End If
            End If
        Next
    End With
    Err.Raise 52
End Sub

Private Sub Command1_Click()
    Recycle2 "D:\File.txt"
    Msgbox "File recycled"
End Sub

Thanks Jx man
i am very thanks full to you.
you solve my problems many time. so Thanks you are a Genius.
Thanks alot

Thanks Jx man
i am very thanks full to you.
you solve my problems many time. so Thanks you are a Genius.
Thanks alot

You're Welcome :)
Don't forget to mark this thread as solved. It will help another members who has same problem like you.

Thank you.

Hello Jx Man i have some problem in this code
when i click on the command botton then it will show a
Run time error 52
if we delete this line to my coding
Err.Raise 52
then it will show Message (Msgbox "File recycled")
but cannot delete my file
please send me again code here is some problem so please tell me
what's wrong
what i do ?
Thanks

when i click on the command botton then it will show a
Run time error 52
if we delete this line to my coding
Err.Raise 52
then it will show Message (Msgbox "File recycled")
but cannot delete my file
please send me again code here is some problem so please tell me
what's wrong
what i do ?
Thanks

I'm sorry, I forgot to mention you to add reference.
Project-> Reference -> Microsoft Shell Controls and Automation
Also make sure that your files is exist.

Is this thread has been resolved?
Plase mark it As SOLVED if it already finished.
If not then post your feedback.

Hello Jx Man i have some problem in this code
when i click on the command botton then it will show a
Run time error 52
if we delete this line to my coding
Err.Raise 52
then it will show Message (Msgbox "File recycled")
but cannot delete my file
please send me again code here is some problem so please tell me
what's wrong
what i do ?
Thanks

Your question is same as before. did u tried what i said above?

sorry brother but it cannot work properly
please check this code again it will show an error
if we delete this line Err.Raise 52 in my code it cannot delete file
please help me

Make sure your file to delete is exist.

Hello Jx man what we doing ?
now i am very Ashamed. because you tell me many time but here is a same problem
when we click to command botton and try to delete the file but show a error
Run-time error 52:
Bad file name or Number

Bad file name or Number

this means your file is not exist. make sure your fle is exist and Check your path is typed correctly.

yes i am sure we create a new junk.txt file in D: drive
and try to delete but we don't know it show an error
err.raise 52 is highlight in yellow color

Hello Jx man we solve this problem 
Acually when we change the file extention in coding then we try to delete the file then its work 
but i have a problem we wer use this function there we have the full path of the file with extention
example 
d:\junk.txt          is a path of file 
but this function is work in
d:\junk
by the way thanks for a good guide for me

Ok. Don't forget to mark this thread as solved

    'The FSO - Microsoft Scripiting Runtime will delete the file permentaly
    'Instead of fso.Deletefile or Kill statement we can use the following code
    'this will send the deleted file to recyle bin

    'Create new form and drag one command button over there, then copy paste
    'the following line of code with the.
    'change the file name, i used it as D:\Text.txt

    Private Declare Function SHFileOperation Lib _
    "shell32.dll" (ByRef lpFileOp As _
    SHFILEOPSTRUCT) As Long

    Private Const ERROR_SUCCESS = 0&
    Private Const FO_COPY = &H2
    Private Const FO_DELETE = &H3
    Private Const FO_MOVE = &H1
    Private Const FO_RENAME = &H4
    Private Const FOF_ALLOWUNDO = &H40
    Private Const FOF_CONFIRMMOUSE = &H2
    Private Const FOF_FILESONLY = &H80
    Private Const FOF_MULTIDESTFILES = &H1
    Private Const FOF_NOCONFIRMATION = &H10
    Private Const FOF_NOCONFIRMMKDIR = &H200
    Private Const FOF_RENAMEONCOLLISION = &H8
    Private Const FOF_SILENT = &H4
    Private Const FOF_SIMPLEPROGRESS = &H100
    Private Const FOF_WANTMAPPINGHANDLE = &H20

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

    'Next create a function called Recycle, like so

    Public Sub Recycle(ByVal strFileName As String)
        Dim CFileStruct As SHFILEOPSTRUCT

        With CFileStruct
            .hwnd = Me.hwnd
            .fFlags = FOF_ALLOWUNDO
            .pFrom = strFileName
            .wFunc = FO_DELETE
        End With

        If SHFileOperation(CFileStruct) <> ERROR_SUCCESS Then
            'An Error Occured
        End If

    End Sub

    Private Sub Command1_Click()
        Recycle "d:\test.txt"
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.