472,802 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 software developers and data experts.

Deleting folder "Temporary Internet Files"

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
5 16677
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
"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
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
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
Hello Kaeli,

Thanks for your posting, it was very helpful!

Cheers
Rosa
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Konrad L. M. Rudolph | last post by:
I hope this is the right NG, please notify me if not. I have got a problem with the "recent files" list of the start page in VS.NET: yesterday I created a new projekt which has the same name as...
3
by: Jim | last post by:
Is it possible to read the Temporary Internet Files folder using C#? I'm messing with FileIO (newbie here) and everything seems to work fine until I try to read the list of files in this Temporary...
2
by: John Saunders | last post by:
I deploy web applications in what may be an odd manner. For every web site "x", I have an "x2" web site which points to an empty directory. I can then use Copy Project in VS.NET to deploy to the...
4
by: Nicolás Castagnet | last post by:
Hi, I write this post because I notice a strange behavior related with "Temporary Internet Files" and maybe some of you can help me to understand it. I am working in a web application with...
1
by: Boris | last post by:
We have some .NET 1.1 DLLs which we want to use in a ASP.NET 1.1 web page (actually one is a real .NET DLL in Managed C++ while the others are native Windows DLLs). First we copied all of the DLLs...
1
by: SalamElias | last post by:
I have a VS 2003 VB web project which works fine, in IE, debug....After several browsing in IE or debugging several ti;mes I start to get the ugly error "Configuration Error ", Access is denied:...
4
by: pedestrian via DotNetMonster.com | last post by:
I'm using VB 2005. How to get the full path for "Program Files" folder in Windows, ie. either it is C:\Program Files or D:\Program Files or etc.? How about the full path of "Windows" folder?...
2
by: Ralf Kaiser | last post by:
Hi, is it possible to define another place where the "Temporary ASP.NET Files" are stored? I do not want to have them on my system partition because i have a separate partition for all the...
3
by: =?Utf-8?B?S2Fyc3RlbiBMdW5kc2dhYXJk?= | last post by:
Hi, I have made an application in C#, where I use the statement Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) to get the name of the "Program Files" folder. It works fine in...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.