By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

Deleting folder "Temporary Internet Files"

P: n/a
Hi,
I'm trying to clear the TIF on Windows XP programmatically with the
below code.
This code works fine on any folder but the TIF. For some reason the
atEnd() statements always defaults to true and no files are deleted in
the folder.
The peculiarity of this issue is that the files/subfolders cannot be
seen through the windows explorer either. I can only access/delete
them through a command shell.
Any ideas?
Many thanks
Rosa
CODE:
################################################## ###########################
// This is the root, which we analyse
var sRoot="C:\\Documents and Settings";
var sLocalSettings="\\Local Settings\\"

// Declaration of other variables
var fso, f, fc, fcf, logfile,TIFFolder, s;
s= "";

// Create the FileSystemObject
fso = new ActiveXObject("Scripting.FileSystemObject");

// Navigate to our root
f = fso.GetFolder(sRoot);

// Log-file
logfile = fso.CreateTextFile("c:\\del.log", 1);
logfile.WriteLine("Logging for the script to delete Temporary Internet
Files Folder");
logfile.WriteLine("=============================== =================================");

// Enumerate all Subfolders to fc, by using the SubFolders-method of
FSO
fc = new Enumerator(f.SubFolders);
for (; !fc.atEnd(); fc.moveNext())
{
// store path to the Temporary Internet Files in TIFFolder
TIFFolder = fc.item() + sLocalSettings + "Temporary Internet
Files";

// dont even try to delete in the following Profiles
if ( (fc.item() == (sRoot + "\\All Users")) ||
(fc.item() == (sRoot + "\\Default User")) ||
(fc.item() == (sRoot + "\\LocalService")) ||
(fc.item() == (sRoot + "\\NetworkService")))
{
continue;
}
// Check, if there is a folder Temporary IE Files
if (fso.FolderExists(TIFFolder))
{

// Now we can delete that folder
try
{
fso.DeleteFolder(TIFFolder);
logfile.WriteLine("FOLDER: " + TIFFolder + " has been deleted
successfully");
}
catch(e)
{
logfile.WriteLine("FOLDER: " + TIFFolder + " Could not be deleted.
--- Error: " +e.number+ " Error-description: " + e.description);
fcf = new Enumerator(f.files);
if (fcf.atEnd())//for TIF this is always true
{
logfile.WriteLine("No files in folder.");
}
else
{
for (; !fcf.atEnd(); fcf.moveNext())
{
s = fcf.item();
try
{
s.Delete();
logfile.WriteLine("FILE: " + s + " has been deleted
successfully");
}
catch(e)
{
logfile.WriteLine("FILE: " + s + " Could not be deleted. ---
Error: " +e.number+ " Error-description: " + e.description);
}
}
} }
}
}
################################################## ############################
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
In article <39**************************@posting.google.com >,
Ro**********@hotmail.com enlightened us with...
the folder.
The peculiarity of this issue is that the files/subfolders cannot be
seen through the windows explorer either.


Probably because they're hidden.

Open Windows Explorer. (just open my documents or something)
Click on Tools -> Folder Options
Click on the View tab.
Where it says "Hidden files and folders", choose the option that says "Show
hidden files and folders".

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
"Rosa" <Ro**********@hotmail.com> wrote in message
news:39**************************@posting.google.c om...
Hi,
I'm trying to clear the TIF on Windows XP programmatically with the
below code.
This code works fine on any folder but the TIF. For some reason the
atEnd() statements always defaults to true and no files are deleted in
the folder.
The peculiarity of this issue is that the files/subfolders cannot be
seen through the windows explorer either. I can only access/delete
them through a command shell.
Any ideas?
Many thanks
Rosa


To bring this on topic, I've converted the script to JScript. I've also
removed the logging, but it should be easy enough to add back in (just
look for where I WScript.Echo() each file I'm deleting).

var TEMPORARY_INTERNET_FILES = 0x20;
var COOKIES = 0x21;

var shell = new ActiveXObject('Shell.Application');

var folder = shell.Namespace(TEMPORARY_INTERNET_FILES);
// or
//var folder = shell.Namespace(COOKIES);

// have to take the -self- property of the namespace to get the actual
object
folder = folder.self;

var path = folder.Path + '\\';
WScript.Echo(path);

var fso = new ActiveXObject('Scripting.FileSystemObject');

var stack = [];
stack.push(fso.GetFolder(path));

while (stack.length > 0)
{
var folder = stack.pop();
for (var en = new Enumerator(folder.Subfolders); !en.atEnd();
en.moveNext())
{
try
{
stack.push(en.item());
}
catch(e)
{
}
}
for (en = new Enumerator(folder.Files); !en.atEnd(); en.moveNext())
{
try
{
// WScript.Echo(en.item().Path);
fso.DeleteFile(en.item().Path);
}
catch(e)
{
}
}
}

Note a couple of things:

1) My version doesn't depend on any "magic" folder names, where ever the
Temporary Internet Files directory resides (for the current user) is
where my script will retrieve it from (so you could set this as a logout
script and it would clear the current user's cache when they log out of
Windows). If you are going to modify it back to do all users, I'd
suggest you try to figure out a more sensible way of determining the
current profile directory, such as reading
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\ProfileList\ProfilesDirectory from the Registry.

2) Notice that I've wrapped the file manipulation code in try-catches.
In this script if there is a problem reading a file -- like, I don't own
it and therefore I get a security violation -- I want to skip the
problem and continue on. I didn't want to write robust error handling
for a script I was giving away for free and I don't use myself.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

P: n/a
Hi Grant,

Thanks for the adaptation. This doesn't however solve the problem
yet...
In regards to Kaeli, the settings are set so that I can see hidden
files and folders. There is just some peculiarity with this particular
folder.

Thanks
Rosa
Jul 23 '05 #4

P: n/a
In article <39**************************@posting.google.com >,
Ro**********@hotmail.com enlightened us with...
Hi Grant,

Thanks for the adaptation. This doesn't however solve the problem
yet...
In regards to Kaeli, the settings are set so that I can see hidden
files and folders. There is just some peculiarity with this particular
folder.


I found this in Google Groups. I think it's relevant here. Looks like you're
not supposed to be able to delete that stuff (TIF) programmatically?

================================================== =======
Message-ID: <OGRVBovlBHA.1552@tkmsftngp02>

As for Temporary Internet Files (TIFs), there is only one proper
method for normally deleting these files. Internet Setting | General Tab |
Delete Temporary Internet Files button. If prompted to delete Offline
Content, do so, especially if you use Outlook Express 5.5 or above. (There's
a bug, that's why.) Simply deleting TIFs using Windows Explorer (or
"Cleanup" programs, for that matter) will not properly update the index.dat
file for that folder. This can lead to problems. You *can* completely delete
the folder, files, index.dat and all, but only in a "pure" DOS setting, and
it's only necessary if there are problems suspected. For more in-depth
descriptions of TIFs, Cookies, and History, go to http://groups.google.com,
use Advanced Search, and look for messages with "Gary Terhune" as Author
(without the quotation marks, though), and "Smoke and Mirrors" in the content
section (this time *with* the quotation marks to indicate an exact phrase.)
================================================== =======

--
--
~kaeli~
Black holes were created when God divided by 0.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5

P: n/a
Hello Kaeli,

Thanks for your posting, it was very helpful!

Cheers
Rosa
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.