IE Temporary Internet Files & Python

R

rtilley

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.

rbt

----------------------------------------

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):
pass
else:
userlist.remove(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:
try:
os.unlink(os.path.join(root, f))
print >> fp, "Removed:", os.path.join(root,f)
except OSError:
pass
fp.close()

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

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

---------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top