How to check whether the temporary Internet files folder is empty before and after deletion?

1.2k views Asked by At

I can use the following to delete IE7's cookies, history, cache, etc. in Ruby.

To clear:

  • the temporary Internet files:

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8') 
    
  • the browsing cookies:

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2') 
    
  • the browsing history:

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1') 
    
  • the form data:

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16') 
    
  • the remembered passwords for filling web login forms:

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32') 
    
  • or delete all the browsing history (all of the above):

    system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255') 
    

Is it possible to get the number of files before and after deletion? Also, how do I check whether the temporary Internet files folder is empty before and after deletion?

1

There are 1 answers

3
joelparkerhenderson On BEST ANSWER

First you need to know where the various folders are.

Example for Windows 7:

C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files

Example for Windows 8:

C:\Users\username\AppData\Local\Microsoft\Windows\INetCache

There may be more than one folder for the temporary files, and sometimes the user can change the location of the folders, so you'll need to read the Windows documentation to find out how to get the complete list of all the folders and their locations.

Also, IE7 is very old. If your Windows version is also very old, you may want to know that Windows has an issue with directory naming using 32-bit vs. 64-bit. This issue can make files and directories seem to disappear. For example: Does Windows 7 hide files from Ruby?

Ruby code to get the directory's files, without the special "dot" directories:

dirname = "C:\Users\username\AppData\Local\Microsoft\Windows\INetCache"
Dir.entries(dirname) - [".", ".."]

Example methods:

def dir_contents(dirname)
  Dir.entries(dirname) - [".", ".."]
end


def dir_empty?(dirname)
  dir_contents(dirname).empty?
end

Example answer:

before_count = dir_contents(dirname).count
... do whatever deletion you want ...   
after_count = dir_contents(dirname).count