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. :bleh: 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. :notworthy
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).
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. :no: So please give some more details about it. Since, I have to submit it sooner, I am requesting you all to help me fast. :notworthy :notworthy
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.
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)'.. :shock: 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.
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. :whistling