few questions

Posts 1–10 of 10 · Page 1 of 1
few questions
hey guys, i had a couple of questions for visual basic 2010

- how could i clear my temp folder & prefetch by using a button . (must work on other peoples computers) and yep ive tried tutorials, didnt work for me
- remove junk files

^ basically things like this, i really would like to make a cleaner!

thanks!
Temp Folder

Code:
Function GetTempDirectory() As String
    Return Environment.GetEnvironmentVariable("TEMP")
End Function
Code:
Dim filePath As String
For Each filePath In Directory.GetFiles(GetTempDirectory())
    Try
        File.Delete(filePath)
    Catch
        ' IGNORE EXCEPTION THROWN
    End Try
Next
Internet Explorer History Path (Maybe useful?)

Code:
Public Function GetHistoryDirectory() As String
    Return Environment.GetFolderPath(Environment.SpecialFolder.History)
End Function
Found these on a website.
All credits go to: iwilld0it



I haven't tested these myself as I do not code in VB but you could give them a go. Good luck.
Quote Originally Posted by Magnificient View Post
Temp Folder

Code:
Function GetTempDirectory() As String
    Return Environment.GetEnvironmentVariable("TEMP")
End Function
Code:
Dim filePath As String
For Each filePath In Directory.GetFiles(GetTempDirectory())
    Try
        File.Delete(filePath)
    Catch
        ' IGNORE EXCEPTION THROWN
    End Try
Next
Internet Explorer History Path (Maybe useful?)

Code:
Public Function GetHistoryDirectory() As String
    Return Environment.GetFolderPath(Environment.SpecialFolder.History)
End Function
Found these on a website.
All credits go to: iwilld0it



I haven't tested these myself as I do not code in VB but you could give them a go. Good luck.
I think directory's are easier to declare as a string. It's shorter...

Dim Cornporn As String = Environment.GetFolderPath(Environment.SpecialFolde r.History)
Quote Originally Posted by Cryptonic View Post


I think directory's are easier to declare as a string. It's shorter...

Dim Cornporn As String = Environment.GetFolderPath(Environment.SpecialFolde r.History)
Look into the DRY principle of development. It's better to wrap something like this in a function if you plan on using it a lot throughout your code. What if the way to get the history/temp path changes? Instead of changing it once in the function definition, you now have to change it in 10000 different places (and even with find+replace you may miss some).
Quote Originally Posted by Jason View Post


Look into the DRY principle of development. It's better to wrap something like this in a function if you plan on using it a lot throughout your code. What if the way to get the history/temp path changes? Instead of changing it once in the function definition, you now have to change it in 10000 different places (and even with find+replace you may miss some).
Can't you just declare it in a module or a class, and you can use it for all of your code? (I think... at school, don't currently have access to VB)
Like I said, I found it on a website so I just passed it along. Thanks for the suggestion though. Now let's hope the OP finds these useful enough.
My next big project is mainly PHP. It's going to be a hosting service for SHSH Blobs/APTickets. If I'm able to I'm going to write software to extract and auto-upload the blobs.
You do realise that cleaning prefetch is actually bad right?
@ Pepsi
Since it won't change, you should store it in a private member.
Calculate once, and store.
Code:
''Private class members
Dim _historyFolderPath as String = "" ''Stored to avoid excessive function calls
...
Form1_load
_historyFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.History) ''copy-pasted from above : un-tested.
End Sub
edit: I guess it depends on your needs/wants: Doing it this way will "make your class a little larger" because you're keeping the string in ram forever, but you don't have to call a function every time you use it, which increases run speed. For this example, you really won't be able to tell the difference (...you probably only call this function *several* times, not several thousand per second).
Yeah, It really won't make too much of a difference, considering it's a small string.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us