"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