Jump to content

Need Batch file help, Please!


tgossen

Recommended Posts

Hello all,

I'm new to the forums and I have tried to search previous posts but have unable to actually locate a working solution to my problem. I am in the process of creating a batch file that will clean up my computer.

The area I am having problems with is deleting the "Temporary Internet Files".

I've tried

DEL "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /F /S /Q

That doesn't work,

I've tried

attrib -a -s -r -h "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

rd /f /s /q "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

md "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

Ok the problem with both of these commands is the the fact that the index.dat file is located in a IE subfolder and i can't delete that. So it basically kills the batch file.

1.) Is there a way to tell the batch not to try and delete the index.dat file?

Thanks for all your help,

T

Link to comment
Share on other sites


You might try this:

for /f "delims=;" %%i in ( 'dir /b "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\" ') do (if not "%%i"=="index.dat" del /F /s /q "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\%%i")

Edited by allen2
Link to comment
Share on other sites

If you're not afraid of vbscript, check http://www.winmag.com/fixes/ie/iecache2.htm:

//
// Internet Explorer Cache Cleanup 2.0
// See http://www.winmag.com/fixes/ie/iecache2.htm
//

var TITLE = "IE Cache Cleanup 2.0";
var wsh = WScript.CreateObject("WScript.Shell");
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var env = wsh.Environment;
var nfiles = 0;
var nbytes = 0;

function delcache(dirname) {
// Open directory name, catch "not found" error
try {
var dir = fso.GetFolder(dirname);
} catch(err) { return err; }
var e;
// Delete files in the current directory
for (e = new Enumerator(dir.files); !e.atEnd(); e.moveNext()) {
var file = e.item();
try { file.Delete(1); } catch (err) { }
}
// Delete subdirectories recursively
for (e = new Enumerator(dir.SubFolders); !e.atEnd(); e.moveNext()) {
var folder = e.item();
delcache(folder);
try { folder.Delete(1); } catch (err) { }
}
return null;
}

function tally(dirname) {
// Open directory name, catch "not found" error
try {
var dir = fso.GetFolder(dirname);
} catch(err) { return err; }
var e;
// Count number and size of files in this directory
for (e = new Enumerator(dir.files); !e.atEnd(); e.moveNext()) {
var file = e.item();
nbytes += file.Size;
nfiles++;
}
// Count files in the subdirectories as well
for (e = new Enumerator(dir.SubFolders); !e.atEnd(); e.moveNext()) {
var folder = e.item();
tally(folder);
}
return null;
}

// Get IE cache directory name from the registry
var IEDIR = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell
Folders\\Cache";
var iecache = "";
try {
iecache = wsh.RegRead(IEDIR);
} catch(err) {}
if ( iecache && fso.FolderExists(iecache) )
iecache = iecache.replace(/\\$/, "");

// Get IE cache max size (in megabytes) from the registry
var IEMAX = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet
Settings\\Cache\\Content\\CacheLimit";
var iemax = 0;
try {
iemax = wsh.RegRead(IEMAX);
} catch(err) {}
if ( iecache.length < 4 || !iemax ) {
wsh.Popup("Cannot determine IE cache directory or settings.",0,TITLE,16);
WScript.Quit(1);
}
if ( !iecache.match(/temp/i) ) {
var msg = "Cache Folder: "+iecache;
msg += "\n\nYour cache folder has a very non-standard name. ";
msg += "There may be a problem with your configuration. No changes made.";
wsh.Popup(msg,0,TITLE+": Too Scary To Delete!",16);
WScript.Quit(1);
}

// Do you really want to go through with it?
tally(iecache);
var mb = Math.round(100*(nbytes/(1024*1024)))/100;
var msg = "Internet Explorer cache will be cleaned:\n\n";
msg += "Folder:\t"+iecache+"\n";
msg += "Maximum:\t"+iemax+" MB\n";
msg += "Currently:\t"+mb+" MB, "+nfiles+" files\n";
if ( mb > iemax )
msg += "(NOTE: Cache space overflow!)\n";
msg += "\nYou will need to reboot to finish cleaning the cache.";
msg += "\nDo you want to continue?";
var yn = wsh.Popup(msg,0,TITLE,36);
if ( yn != 6 ) {
wsh.Popup("Cancelled at your request. No changes made.",0,TITLE,16);
WScript.Quit(4);
}

// Create batch file that will run on boot
//var tmp = env("TEMP") || env("windir")+ "\\Temp";
//var batfile = tmp+"\\iecache!.bat";
var batfile = "C:\\iecache!.bat";
var fh = fso.CreateTextFile(batfile, true);
fh.WriteLine("prompt $G ");
fh.WriteLine(iecache.substr(0,2));
fh.WriteLine("cd \""+iecache+"\"");
try {
fso.GetFolder(iecache+"\\content.ie5");
fh.WriteLine("cd content.ie5");
} catch(err) { }
fh.WriteLine("attrib -r -h -s index.dat");
fh.WriteLine("del index.dat");
fh.WriteLine("rem ------ IE Cache cleanup complete, please close this window.
------");
fh.Close();

// Goodbye cache, hello disk space!
delcache(iecache);
var ROKEY =
"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunServicesOnce";
wsh.RegWrite(ROKEY+"\\ClearCache", batfile);

msg = "Please reboot NOW to complete the\nInternet Explorer cache cleanup.";
wsh.Popup(msg,0,TITLE,64);
WScript.Quit(0);

Link to comment
Share on other sites

Hello all,

I'm new to the forums and I have tried to search previous posts but have unable to actually locate a working solution to my problem. I am in the process of creating a batch file that will clean up my computer.

The area I am having problems with is deleting the "Temporary Internet Files".

I've tried

DEL "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /F /S /Q

That doesn't work,

I've tried

attrib -a -s -r -h "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

rd /f /s /q "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

md "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\"

Ok the problem with both of these commands is the the fact that the index.dat file is located in a IE subfolder and i can't delete that. So it basically kills the batch file.

1.) Is there a way to tell the batch not to try and delete the index.dat file?

Thanks for all your help,

T

At the risk of being flamed, AGAIN, here goes.

I had the same idea years ago and have been writing my own cleanup batch files ever since. They now run on PC's all over the world.

My Windows 98/ME batch file is called "Hoover.bat" and my XP cleanup program is called "XPCleanup.bat".

All you need to run the XPCleanup.bat program is the old DOS command, "Deltree.exe". You can download it Here.

Just put it in your C:\Windows\System32 folder and forget about it.

Here's the generic version of my own XPCleanup.bat program: Use what you need.

************************************************

Rem: Copy the following text into a new wordpad document.

Rem: To save this listing as a batch file; Click 'File' then click 'Save Page as...'

Rem: Keep the name as it is, and save it to your desktop of ease of use.

Rem: The Deltree.exe command must be in your C:\windows\system32

Rem: folder before this program will run.

Rem: This command can be found in any system running Windows 98 or ME. I've also

Rem: placed this program on my webpage for easy access.

Rem: The /y after deltree tells deltree to execute the command without stopping to ask if it's OK.

Rem: The lines that do not adhear to the DOS 8+3 filename structure must be in quotes.

cls

deltree /y C:\temp\*.*

deltree /y %SystemRoot%\temp\*.*

deltree /y "%SystemRoot%\system32\config\systemprofile\cookies\*.*"

deltree /y "%SystemRoot%\SYSTEM32\config\systemprofile\Local Settings\History\History.IE5\*.*"

deltree /y "%SystemRoot%\SYSTEM32\config\systemprofile\Local Settings\Temporary Internet Files\*.*"

deltree /y "%SystemRoot%\SYSTEM32\config\systemprofile\Local Settings\Temp\*.*"

deltree /y "C:\Documents and Settings\Default User\Local Settings\Temporary Internet Files\Content.IE5\*.*"

deltree /y "C:\Documents and Settings\Default User\Local Settings\History\History.IE5\*.*"

deltree /y "C:\Documents and Settings\Default User\Local Settings\Temp\*.*"

Rem: No need to duplicate the following section for each registered User

deltree /y "%USERPROFILE%\Cookies\*.*"

deltree /y "%USERPROFILE%\recent\*.*"

deltree /y "%USERPROFILE%\Local Settings\cookies\*.*"

deltree /y "%USERPROFILE%\userdata\*.*"

deltree /y "%USERPROFILE%\Local Settings\History\*.*"

deltree /y "%USERPROFILE%\Local Settings\Temp\*.*"

deltree /y "%USERPROFILE%\Local Settings\History\Temporary Internet Files\Content.IE5\*.*"

deltree /y "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\*.*"

deltree /y "C:\Documents and Settings\NetworkService\Cookies\*.*"

deltree /y "C:\Documents and Settings\NetworkService\Local Settings\History\History.IE5\*.*"

deltree /y "C:\Documents and Settings\NetworkService\Local Settings\Temp\*.*"

deltree /y "C:\Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5\*.*"

deltree /y "C:\Documents and Settings\LocalService\Local Settings\History\History.IE5\*.*"

deltree /y "C:\Documents and Settings\LocalService\Local Settings\Temporary Internet Files\Content.IE5\*.*"

deltree /y "C:\Documents and Settings\LocalService\Local Settings\Temp\*.*"

deltree /y "C:\Documents and Settings\LocalService\Cookies\*.*"

deltree /y "C:\Documents and Settings\Administrator\Local Settings\Temp\*.*"

deltree /y "C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\*.*"

deltree /y "C:\Documents and Settings\Administrator\Local Settings\History\*.*"

deltree /y "C:\Documents and Settings\Administrator\Cookies\*.*"

************************************************

to delete additional junk, just put the path to it in an additional line and add it to the file.

for instance:

deltree /y "C:\Program Files\CallWave\Calls\*.*"

deletes the old messages stored by my CallWave program.

I hope you can use this as a guide to create your own custom cleanup program.

I still use Deltree.exe because it can be used to delete just one file or a group of files or an entire tree structure. It's all in how you write the path statement. No need to rip out a whole sub directory, when all you want to delete is a single file or file type.

Good Luck,

Andromeda43 B)

Link to comment
Share on other sites

Andromeda,

Windows XP doesn't use deltree. There's no need for the extra program either. A little research on your part would show you that rd and rmdir are both commands integrated to remove directories. You can also learn that from reading everyone's posts here as they cover that quite nicely. ;)

About the rmdir command - by Microsoft. You can learn more about the command line changes here.

deltree

The rmdir /s command deletes directories containing files and subdirectories. For more information about the rmdir command, see Rmdir

tgossen,

Aside from the .bat files, you may also wish to use Firefox 2.0. You can set it to clear all your private data when the browser closes. You can find it under Privacy. Another alternative is to use CCleaner to remove everything you don't want/need.

Hope this helps. :D

Link to comment
Share on other sites

There's no need for the extra program either. A little research on your part would show you that rd and rmdir are both commands integrated to remove directories.

You can also learn that from reading everyone's posts here as they cover that quite nicely

I still use Deltree.exe because it can be used to delete just one file or a group of files or an entire tree structure. It's all in how you write the path statement. No need to rip out a whole sub directory, when all you want to delete is a single file or file type.

:whistle:

jaclaz

Link to comment
Share on other sites

Windows XP doesn't use deltree. There's no need for the extra program either. A little research on your part would show you that rd and rmdir are both commands integrated to remove directories. You can also learn that from reading everyone's posts here as they cover that quite nicely. newwink.gif

There you go again. Lying to people. Neither of those commands can remove just one file from a sub directory or a group of files of the same type, like .xyz.

XP uses Deltree.exe just fine. MS removed it from the list of external DOS commands in XP, but all you have to do it put it back. I clearly explained how to do that and where to get it. I do wish you'd read more carefully before you turn on the flames.

Yous guys are always telling people to download this program or that program to do something, but when I say to acquire Deltree.exe to do a certain job, you flame me and basically call me a liar. You know....I'm really getting sick of it.

Thousands of people worldwide are using Deltree.exe and my XPCleanup.bat program to keep their computers free of junk buildup with never the first problem.

A shortcut to the batch file can even be put in the startup folder for a FREE cleanup on every boot.

If you don't want to use Deltree.exe or a batch file to clean up your computer, then don't, but stop calling me a liar every time I try to answer someone's question.

He asked how to write a batch file....not how to use Firefox or some other method to eliminate internet files.

If you can't help with the man's question, then why not just remain silent.??? :realmad:

Link to comment
Share on other sites

... \Temporary Internet Files\*.*" ...
There you go again. Lying to people. Neither of those commands can remove just one file from a sub directory or a group of files of the same type, like .xyz.

*.* means all files, I know quite well how to read. :)

XP uses Deltree.exe just fine. MS removed it from the list of external DOS commands in XP, but all you have to do it put it back. I clearly explained how to do that and where to get it. I do wish you'd read more carefully before you turn on the flames.

Yous guys are always telling people to download this program or that program to do something, but when I say to acquire Deltree.exe to do a certain job, you flame me and basically call me a liar. You know....I'm really getting sick of it.

Thousands of people worldwide are using Deltree.exe and my XPCleanup.bat program to keep their computers free of junk buildup with never the first problem.

A shortcut to the batch file can even be put in the startup folder for a FREE cleanup on every boot.

If you don't want to use Deltree.exe or a batch file to clean up your computer, then don't, but stop calling me a liar every time I try to answer someone's question.

He asked how to write a batch file....not how to use Firefox or some other method to eliminate internet files.

If you can't help with the man's question, then why not just remain silent.??? :realmad:

Yes, we can either use your limited use batch file or use CCleaner which will cover a much wider spectrum of cleanup. Tough choice. ;)

There is no harm in offering alternatives. After all, that is one of the purposes of these forums. I simply said that the use of deltree is not needed and really is incorrect for Windows XP. Windows XP makes use of rd / rmdir which suits the needs of the original poster.

Now; there's no need to flame me or call me a liar. The only person who has called you a liar is... well... you. Just be respectful to all your fellow posters, after all; we're all here to help, no matter who we are.

Link to comment
Share on other sites

Windows XP doesn't use deltree. There's no need for the extra program either. A little research on your part would show you that rd and rmdir are both commands integrated to remove directories. You can also learn that from reading everyone's posts here as they cover that quite nicely. newwink.gif

There you go again. Lying to people. Neither of those commands can remove just one file from a sub directory or a group of files of the same type, like .xyz.

XP uses Deltree.exe just fine. MS removed it from the list of external DOS commands in XP, but all you have to do it put it back. I clearly explained how to do that and where to get it. I do wish you'd read more carefully before you turn on the flames.

Yous guys are always telling people to download this program or that program to do something, but when I say to acquire Deltree.exe to do a certain job, you flame me and basically call me a liar. You know....I'm really getting sick of it.

Thousands of people worldwide are using Deltree.exe and my XPCleanup.bat program to keep their computers free of junk buildup with never the first problem.

A shortcut to the batch file can even be put in the startup folder for a FREE cleanup on every boot.

If you don't want to use Deltree.exe or a batch file to clean up your computer, then don't, but stop calling me a liar every time I try to answer someone's question.

He asked how to write a batch file....not how to use Firefox or some other method to eliminate internet files.

If you can't help with the man's question, then why not just remain silent.??? :realmad:

Andromeda43, No one is lying to anyone here. All Tarun was saying is there is no need for additional software when you can achieve the same thing with what you already have.

People reccommend programs that help keep there systems clean, or running smoothly, and there is nothing wrong with that. However if you are making your own scipt, you don't need outside sources to make your software work if you can use what you already have.

Oh and this is how you delete a single file in a directory called tmp "del tmp\file.txt" ;) "del tmp/*.txt" will delete all .txt files

Edited by joshg678
Link to comment
Share on other sites

Thanks, this worked like a charm.

tgossen's question has been answered.

7.b This community is built upon mutual respect. You are not allowed to flame other members. People who do not respect personal opinions and/or personal work will be warned in first instance. If you ignore the warning and keep on flaming, you will be banned without notice.

[ closed ]

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...