Results 1 to 40 of 40

Threaded View

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009

    Temp File Cleaner

    Every now and then, I'll see people ask how to get the temp files for some location. It's usually places like IE's directories, or the system temp, etc. In one of my other projects, I use CCleaner to clear up temp files prior to other automated tasks and I wanted to decrease my dependency on 3rd party software. So I decided to duplicate the features of CCleaner in my own app, I'm temporarily calling it ACleaner. I couldn't think of a name, so that's what I got :P

    I decided that I wanted to share this with everyone, so if anyone wanted to do something similar or needed to know a temp path, etc, this would help them. But, before I continue, please be aware of two things.

    1. You can use my work in any way, just don't take credit for it.
    2. It's not quite complete. It's mostly done because all of the "hard" work is done, but there are still some small things to finish up.

    With that, let's move on to the code!

    When I first started making this, I tried to keep ease of use in mind. I wanted anyone who wanted to use it, would be able to with just a few lines of code. So, if anyone has any better ideas on how I'm doing this, please let me know.

    There are 4 main classes to be aware of.

    FileInfoA, DirectoryInfoA, RegistryInfoA, and UniducksCleaner.

    The last class is what actually does all of the work and the other three are just classes to pass information to the worker class. For the moment, you can't scan any registry keys, but I should finish that up soon. So no worries there.

    With the worker class, since I'm working with a ListView, I hard coded the ListView into the class, which isn't ideal, but was the easiest option at the time. I'll probably go back later and remove that so it just returns a list that can be manipulated.

    Before you can start scanning, you need to create a new instance of the the "Info" classes and pass them to the new instance of the worker class you created. Again, the registry isn't working yet, so I'll show an example for the other classes.

    VB.NET Code:
    1. Dim cleaner As New UniducksCleaner 'Worker Class
    3. Dim di As New DirectoryInfoA(InternetExplorerCookies, "Internet Explorer - Cookies", 3, "*.*", True)
    4. Dim fi As New FileInfoA(GoogleChromeCookies, "Google Chrome - Cookies", 1, "*.*")
    5. Dim ri As New RegistryInfoA("hkcu", VisualStudio2010FileMRUList, False, "Visual Studio - VS 2010 File MRU List", 13)
    7. cleaner.Add(di)
    8. clean.Add(fi)
    9. cleaner.Add(ri)

    The Add method only accepts a FileInfoA, DirectoryInfoA or a RegistryInfoA class. You can't pass a normal string to it becuase the other classes force you pass additional information the worker class needs to execute properly.

    For the DirectoryInfoA class, there are 5 arguments, but they're pretty simple. I'll list them in order.

    1. Path to file or directory. You'll notice I just passed a premade string here. All of the strings I've compiled are in the "Paths" module.
    2. This is just a description for the ListView
    3. ImageIndex for the ListView
    4. Search filter.
    5. If True, the worker class will recurse through the directory.

    The FileInfoA class has just the first 4 and the RegistryInfoA class has just two.

    After you've added the info classes, just call Scan.

    All of the paths are kept in a module called, "Paths", so if you just need to know where a particular temp location is, just check there.

    I've probably missed some information, so just check out the sample project and play around with it. Please feel free to ask any questions.

    I changed the scanning methods to make them a lot more accurate.
    I also added more directories.
    Added some UI features and changed other UI features up a little bit.

    *UPDATE 2*
    Fixed a few small bugs
    Finished adding all current directories and files

    *UPDATE 3*
    Added basic registry scanning - Current registry MRUs = VS 2010 File/Project MRU Lists
    Attached Files Attached Files
    Last edited by weirddemon; Aug 2nd, 2011 at 11:41 AM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

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


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.