Delete temp files and count them

Hewlett-packard / Sd2100
December 30, 2009 at 17:14:44
Specs: Windows 7, 1024
how would i go about deleting internet temp files and whats deleted have them counted from a log file.

del \s \f \q %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.* >log.txt

that doesnt delete them nor count why is that?

all i would like to do is count them and delete what counted from log.txt.

See More: Delete temp files and count them

Report •

December 30, 2009 at 19:18:30
slashes the wrong way (backward) in
del \s \f \q %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.* >log.txt

try changing to
del /s /f /q %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.* >log.txt

Report •

December 30, 2009 at 19:38:59
opps i knew that :), but the thing of it is your line the "correct" line still wont work because non or most of the temp files dont have an extentions so they wont delete. so the *.* doesnt work, not sure way.

is there a way to use the RMDIR and count the files that are removed/deleted?

Report •

December 30, 2009 at 21:17:22
might be an o.s. thing since it worked here on winXp pro, (with *.* and without as *)
no way i know that rmdir will tell you how many were del'd. but here is one klunky method:
for /f "tokens=1 delims=F" %%a in ('dir /s /a-d ^| find " File(s) "') do (
set /a p+=%%a
:this is just for reference
echo %%a)
:this should be total no. of files
echo %p%

other klunkey method is count the lines in the logfile, then pipe the "del /s" out to your logfile, then count again and
subtract (dif=newct-oldct).

I'm kinda in the dark (as is usual with me) esp. about:
*all i would like to do is count them and delete what counted from log.txt*

Report •

Related Solutions

December 31, 2009 at 11:23:22
for some reason its not counting the files very well, its saying i have around 2500 in the internet temp file, when i only have 625.

what would cause this? im running window 7 but *.* wont delete the files for some reason, if any one has Vista that know a way to delete all file then count whats deleted that would be great.

Report •

December 31, 2009 at 13:41:22
the wrong count is "almost" exactly 4 times the alleged actualfilecount. hm. i did find error in my script, but it should
have been exactly twice the actual count: the "grand total" at the end of the "dir" would cause the number to be doubled.
make sure that the accumulator variable is initialized to zero (i called it "p", so: set /a p=0) before entering the loops and make sure to setlocal at begin.

run the primary manually from the commandprompt and see what it yields (you've prob'ly already done that, to arrive at the 625):
dir /s /a-d | find "File(s)"
attrib /s *.* | find /v /c ""
this will count the files
to see if the numbers add up right.

method 2:
:first count the lines in logfile
find /c /v "" < log.txt > precount
:: run two "del"s if system won't clear them all using *
del /s /f /q %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.* >>log.txt
del /s /f /q %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*. >>log.txt
find /c /v "" < log.txt >> precount

now the precount file should have two numbers, the difference of which is the no. of files deleted.
for /f %%a in (precount) do (
set /a bb=xx
set /a xx=%%a)
set /a xx-=bb
echo %xx% files deleted

i have feeling i'm making things much more complicated than they should be... hopefully you will get better assist.

Report •

December 31, 2009 at 15:11:27
thank you for you help,

what i dont understand is if you open the DIR where the internet temp file are, and you 'select all' it shows 625files in the dir, BUT useing the code you gave me works but it says there are 2289 files, why is that?

i used this code to get my numbers

dir "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files" /b/s/a-d |find /v /c "::"

Report •

December 31, 2009 at 17:07:26
your code seems to work fine here, but i'm running all this on my winME machine because the winXp does not access the internet. so my temp files are stored differently, but i used explorer gui to access one of the IE cachefile directories and it gave me the same count as your batch as well as the methods i suggested. the only thing i can think of is just do a dir /b/s , from the root of the tempfiles directory, out to a textfile and see if the output matches (ie, there are indeed 625 files listed) Also, the /s will descend into subdirectories, whereas the gui "select all" from the root will only give count of files in the root.
I'm the same way, if there's a discrepancy in reporting, i would want to find out the reasons behind it.

Report •

December 31, 2009 at 22:08:00
how could i go about puting the number in a variable and echo it?

dir "%userprofile%AppData\Local\Microsoft\Windows\Temporary Internet Files" /b/s/a-d |find /v /c "*.*"

Thank you again

Report •

January 1, 2010 at 04:26:30
Brock, take care when you are counting files, there can be only one number correct.

In Explorer, make sure you have checked/unchecked the option where it says to show hidden files, system files, etc...

And, as stated above, when using the DIR command, make sure the he is displaying all types.
Nbrane, isn't this missing then:


... in order to show hidden and system files ? From the DIR command, it is not really 100% clear what is default action, showing or hiding either Hidden and System files. I guess it is "showing".

Brock, to show the number of files, you need to remove /B again since /B will show only names of files, no info on file numbers and sizes

And note that /S is showing/counting files in subdirs as well. You aren't comparing files in a directory, with the files in a directory and subdirectories ?!

Report •

January 1, 2010 at 08:54:54
yes i want to count all files include sub DIR, i want to delete all temp file but have a count of all file/subdir, and also would like to see the number be placed in a variable.

Report •

Ask Question