IE Temporary Internet Files & Python

rtilley rbt at
Thu Nov 10 15:37:18 CET 2005

A bit off-topic, but Python related.

Below is a script that recursively deletes files from a directory. It 
works well on the two directories that I'm currently using it on:

C:\Documents and Settings\user\Cookies
C:\Documents and Settings\user\Temp

However, I'd like to use it on this directory as well:

C:\Documents and Settings\user\Temporary Internet Files

The script does not seem to work when used on Temporary Internet Files. 
I've googled around a bit, but haven't found any tips... thought I'd 
trouble the list for an answer or at least some explanations.

Feel free to critiqe the script as well. Perhaps it's a programmer error.



import os
import os.path

userpath = 'C:/Documents and Settings/'
userlist = os.listdir(userpath)

# Make sure that userlist only contains directories, no files.
for u in userlist[:]:
     if os.path.isdir(userpath+u):

def remove_files(target_dir):
     fp = file('remove_temp_files.txt', 'a')
     for root, dirs, files in os.walk(target_dir):
         for f in files:
                 os.unlink(os.path.join(root, f))
                 print >> fp, "Removed:", os.path.join(root,f)
             except OSError:

# Remove 'Local Settings|Temp' files
for username in userlist:
     target_dir = userpath+username+'/Local Settings/Temp/'
     #print target_dir

# Remove IE Cookies
for username in userlist:
     target_dir = userpath+username+'/Cookies/'
     #print target_dir


More information about the Python-list mailing list