Solved

delete temporary internet files

Posted on 2002-04-29
7
309 Views
Last Modified: 2013-11-20
How can i delete temporary internet files programmaticaly using microsoft visual c 6.0?
0
Comment
Question by:spap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6977329
Hi spap,

you can use SHGetFolderPath() with arg 'CSIDL_INTERNET_CACHE' to retrieve
the folder where Temporary Internet Files are stored and with this folder you can
use i.e. SHFileOperation() to delete all files using wildcards.

hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:spap
ID: 6983552
Dear Zoppo the problem is that the cookies or the temporary internet files are system files. as a result the deletion fails to delete the files. what to do about that?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6985433
Hmm, bad ... I found that with following code I could delete all those files/cookies:

void CleanDir( TCHAR* szPath, int& iFileCount )
{
 WIN32_FIND_DATA FindFileData;
 HANDLE hFind;

 TCHAR szSubPath[256];
 strcpy( szSubPath, szPath );

 strcat( szSubPath, "\\*.*\0" );

 hFind = FindFirstFile( szSubPath, &FindFileData );

 if (hFind == INVALID_HANDLE_VALUE)
 {
  cout << "Invalid File Handle. Get Last Error reports " << GetLastError() << endl;
  return;
 }

 BOOL bOk = TRUE;
 while ( bOk )
 {
  if ( 0 != stricmp( FindFileData.cFileName, ".." ) && 0 != stricmp( FindFileData.cFileName, "." ) )
  {
   if ( FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes )
   {
    strcpy( szSubPath, szPath );

    strcat( szSubPath, "\\" );
    strcat( szSubPath, FindFileData.cFileName );

    CleanDir( szSubPath, iFileCount );
   }
   else
   {
    cout << "Delete File " << FindFileData.cFileName << " ... ";
 
    strcpy( szSubPath, szPath );

    strcat( szSubPath, "\\" );
    strcat( szSubPath, FindFileData.cFileName );
 
    if ( 0 != unlink( szSubPath ) )
     cout << "Error deleting file: " << GetLastError() << endl;
    else
    {
     iFileCount++;
     cout << "File deleted!" << endl;
    }
   }
  }
 
  bOk = FindNextFile( hFind, &FindFileData );
 }

 FindClose(hFind);
}

void DeleteTempIEFiles()
{
 TCHAR szPath[_MAX_PATH];

 SHGetFolderPath
 (
  NULL,
  CSIDL_INTERNET_CACHE,
  NULL,
  SHGFP_TYPE_CURRENT,
  szPath
 );

 cout << "Folder for temporary internet files is : " << endl << "'" << szPath << "'" << endl;

 int iFileCount = 0;

 CleanDir( szPath, iFileCount );

 cout << iFileCount << " Files deleted!" << endl;
}

hope this helps,

ZOPPO
0
 
LVL 1

Author Comment

by:spap
ID: 6985692
Thanks zoppo. It works perfect.
For the completeness of the porposed answer do you know how to remove the items from the address bar of the internet explorer programmaticaly?

Thank again and best wishes from Greece.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 6985710
Hi again,

nice to hear it works :o)

to remove history from address bar (I hope you meant the history) you simply need to remove
all entries from registry key HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs

ZOPPO

PS: Greetings from Germany, too ... I bet you have the better weather.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question