wtkm

using the following code to delete file to recycle bin does take a plenty of time if i delete a file by a file in large quantity (compare the method of deleting the files permanently).

Option Explicit

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 Long '  only used if FOF_SIMPLEPROGRESS
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40

Private Sub CmdDelete_Click()
Dim op As SHFILEOPSTRUCT

    With op
        .wFunc = FO_DELETE
        .pFrom = FilenameText.Text
        .fFlags = FOF_ALLOWUNDO
    End With
    SHFileOperation op
End Sub

 

 

 

 

Is there any method for me to speed up the deletion process to recycle bin  

 

Thanks.



Re: Visual Basic General How to make deletion of files faster

spotty

Is there any reason you are using unmanaged API's to delete files rather than the using the managed classes in .NET Framework. My thoughts are that it is probably for speed purpose, but just curious as I try to discourage using unmanaged API's if possible where a managed function exists.





Re: Visual Basic General How to make deletion of files faster

wtkm

may i know what do u mean by the "unmanaged API's" and "managed function exist"

As far as I know, to do the far deletion to the rcycle bin, myself only have such source code. Mind to tell me more

Thanks





Re: Visual Basic General How to make deletion of files faster

spotty

The following will create a file and send the file to the recycle bin

My.Computer.FileSystem.WriteAllText("c:\test.txt", "dddsd", False)
My.Computer.FileSystem.DeleteFile("C:\test.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

My.Computer.Filesyste,DeleteFile
http://msdn2.microsoft.com/en-us/library/5fbah944.aspx

Look at the SendToRecycleBin option

Managed Code
http://en.wikipedia.org/wiki/Managed_code

Calling directly to the unmanaged API's increases your risks of doing something which can crash the entire machine. Managed functions are those functions whcih run in the .NET Framework and run on a virtual machine. (.NET Framework). A web search on managed Code will reveal quite a bit, including the additional risks involved which may be high - basically if there is a function in the .net framework its best to use that where possible to make you application as robust as possible.





Re: Visual Basic General How to make deletion of files faster

wtkm

Thanks for ur times and ur answers. I appreciate it. thx.

by the way,could the VB6.0 use the My.Computer.FileSystem. command





Re: Visual Basic General How to make deletion of files faster

spotty

 No, VB6 does not use the the .NET framework.   My functionality is available in VB.NET 2005

The only way I could think to use this would be to create a .NET class library with this functionality and then use the COM Interop to wrap it up and make it accessible to VB6 - but this would not be a recommended option if your talking about speed.

These forums are for VB.NET and there are better places to find answers for older versions of VB. Maybe the

VB6 newgroups - http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.vb.general.discussion&lang=en&cr=US

Or perhaps the VB6 resource center
http://msdn.microsoft.com/vbrun/

or  perhaps www.vbcity.com may be useful places to search for answers on VB6 related questions.

I really would suggest ditching the VB6 and downloading the VB Express from the microsoft web site for free and using this.   Its the latest technology and your then in the right place to ask questions in this forum.

 Hopefully this helps.