Results 1 to 6 of 6

Thread: Visual Studio 2010: Moving files to the trash

  1. #1
    Join Date
    Sep 2010
    Posts
    26

    Visual Studio 2010: Moving files to the trash

    Hello everyone, since I could not find the old post, so I asked them the question ... now I write it here XD I hope is not a problem. this is the code to delete temporary files:
    Code:
    Dim size As Long
             As Long Dim sizeTemp
             Dim inf As System.IO.FileInfo
             Dim con As Integer = 0 Dim totLen As Double = 0
    
             For Each foundFile As String In My.Computer.FileSystem.GetFiles (My.Computer.FileSystem.SpecialDirectories.Temp, _
                                                                             Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    
                 count = count + 1
                 Try
                     info = New System.IO.FileInfo (foundFile)
                     sizeTemp = info.Length
                     System.IO.File.Delete (foundFile)
                     size + = sizeTemp
                     ListBox.Items.Add (foundFile)
                 Catch ept As Exception
                 Finally
                     info = Nothing
                 End Try
             Next
    But if I wanted to just move them to the trash? I tried to change but it gives me error .. like it? I am sure that someone over there must have some solutions for this. Please help me out.

  2. #2
    Join Date
    Oct 2008
    Posts
    105

    Re: Visual Studio 2010: Moving files to the trash

    I think that you should add some more in the coding while integrating. Try the following code, which can be useful for moving the files in trash.
    Code:
    MyComputer.FileIO.DeleteFile (foundFile, FileIO.UIOption, FileIO.OnlyErrorLogs.RecycleOption.SendToRecycleBin)
    Even after implementing this code, if you are getting some error then provide more details of the error message along with the modified code. Sure there would be someone for your help (if I am not able to).

  3. #3
    Join Date
    Sep 2010
    Posts
    26

    Re: Visual Studio 2010: Moving files to the trash

    The code is there, just that I would turn to "permanently delete files" in "move files to trash". And as the delete command is in the try, I do not know how. I tried! really!! Only that wherever I put the move command and not for the delete, it gives me an error, sometimes the same at different times ... but I do not know where to put it. So please give some more details about it. Since, I have to submit it sooner, I am requesting you all to help me fast.

  4. #4
    Join Date
    May 2008
    Posts
    255

    Re: Visual Studio 2010: Moving files to the trash

    But sorry, that code you wrote yourself? Try if you hide the exception that occurs inside a little bad, you can always remove the Try or run the code line by line and see what happens. VS debugging systems are many, I do not see what the problem is: you can put a breakpoint and then execute the code line by line to see where it stops running ... At that point you will come to know where exactly the problem is residing.

  5. #5
    Join Date
    Sep 2010
    Posts
    26

    Re: Visual Studio 2010: Moving files to the trash

    If I delete and try to move I put the code directly into the trash, it works, but I would try to stay on, because with it, when it finds files in use, skip them without giving errors. In the end I need to try this and to show the files in listview. Finally, it gives me error after start debugging, but take it from me first, that makes me not even start debugging, and tells me that I must first correct the errors. The following is the code now :
    Code:
    For Each foundFile As String In My.Computer.FileSystem.GetFiles (My.Computer.FileSystem.SpecialDirectories.Temp, _
                                                                             Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    
                 count = count + 1
                 Try
                     info = New System.IO.FileInfo (foundFile, FileIO.UIOption.OnlyErrorLogs, FileIO.RecycleOption.SendToRecycleBin)
                     sizeTemp = inf.Length
                     System.IO.File.Delete (foundFile)
                     size + = sizeTemp
                     ListBox.Items.Add (foundFile)
                 Catch exp As Exception
                 Finally
                     inf = Nothing
                 End Try
             Next
    Here tells me: Overload resolution failed because no 'New' accepts this number of subjects available.
    While trying another way :
    Code:
    For Each foundFile As String In My.Computer.FileSystem.GetFiles (My.Computer.FileSystem.SpecialDirectories.Temp, _
                                                                             Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    
                 count = count + 1
                 Try
                     inf = New System.IO.FileInfo (foundFile)
                     sizeTemp = info.Length
                     System.IO.File.Delete (foundFile, FileIO.UIOption.OnlyErrorLogs, FileIO.RecycleOption.SendToRecycleBin)
                     size + = sizeTemp
                     ListBox.Items.Add (foundFile)
                 Catch exp As Exception
                 Finally
                     inf = Nothing
                 End Try
             Next
    but here I get this: Too many arguments to 'Public Shared Sub Delete (path As String)'.. I'm not understanding anything! I want to integrate the command to move files to the trash directly into this and I do not want to try a different code.

  6. #6
    Join Date
    Apr 2009
    Posts
    78

    Re: Visual Studio 2010: Moving files to the trash

    The line posted need to move the file to the trash, it is obviously putting in place of the similar line in the original code deletes the file permanently. Does not even fit, to make things easier it has also taken the trouble to insert the variable used in your code. You just do a nice cut and paste, that's all. If you can not do this simple task is evident that you have not tried at all to understand the meaning of the original block of code, but are simply trying to run it with a hammer.

Similar Threads

  1. Replies: 2
    Last Post: 16-02-2011, 01:49 PM
  2. How to run Silverlight 4 in Visual Studio 2010
    By wllwnn in forum Tips & Tweaks
    Replies: 1
    Last Post: 05-08-2010, 01:32 AM
  3. Can't install visual studio 2010
    By DarkShadow in forum Windows Software
    Replies: 4
    Last Post: 18-02-2010, 08:13 PM
  4. Compare Visual Studio 2010 and Visual Web Developer Express
    By Zacharia in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 03:27 AM
  5. Microsoft Visual Studio 2010
    By kelfro in forum Software Development
    Replies: 1
    Last Post: 21-01-2009, 05:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •