Batch delete *.tmp files and tell MB of data

Toshiba Satellite l505d-s5965 notebook
March 31, 2010 at 06:19:13
Specs: Windows 7, 1024
What im trying to do is

over the whole C: drive 'C:\*.tmp' i want to delete and calulate the data in MB then delete.

i how to delete but cant figure out how to calculate the files size amount of data deleted.

thank you
Brock


See More: Batch delete *.tmp files and tell MB of data

Report •


#1
March 31, 2010 at 06:33:05
Do a search on C:\ for all "*.tmp" files.

In the results window, select all the files you want to delete, right-click and then select 'properties'. Size should be shown in the pop-up that appears.


Report •

#2
March 31, 2010 at 06:33:50
EDIT: ^^^^ That's not a programming solution. ^^^^

dir C:\*.tmp /s


Report •

#3
March 31, 2010 at 06:42:38
thanks razor, how could i put that in a variable?

EDIT: Also that number is in bytes how come i convert that into megabytes also?

thank you again
Brock


Report •

Related Solutions

#4
March 31, 2010 at 07:08:55
Using "SET /A" will cover the maths required to calculate between megabytes and bytes

Concerning the volume, what you can do is have a wrapper script on file deletion, and when deleting a file, have it counting how big the file is, then add that to a sum


Report •

#5
March 31, 2010 at 07:11:03
Here's how you put in a variable(for english language XP at least):

@for /f "tokens=1-5" %%a in (' dir /a/s/-c c:\*.tmp') do if "%%d"=="bytes" if not "%%e"=="free" set tmpbytes=%%c
@del /s c:\*.tmp

If you have less than 2gb on a 32bit system converting to
mb(divide by 1048576) is easy, larger that that and you have
to start jumping through hoops(trust me I have done it, it's
not pretty).

EDIT:
@tvc

Using "SET /A" will cover the maths required to calculate between megabytes and bytes

Not if the total file size is greater than 2gb on a 32bit system......


Report •

#6
March 31, 2010 at 07:31:56
Thanks everyone just what i needed

Report •

#7
March 31, 2010 at 07:43:20
one last question

that code

@for /f "tokens=1-5" %%a in (' dir /a/s/-c c:\*.tmp') do if "%%d"=="bytes" if not "%%e"=="free" set tmpbytes=%%c
@del /s c:\*.tmp


does that work if i where to use *.* in a %temp% for example?


Report •

#8
March 31, 2010 at 07:50:40
Should work on anything dir will list and calculate.

Report •

#9
March 31, 2010 at 11:12:09
If there is more than 2 gig of TMP files, you may have an issue ;)

Report •

#10
March 31, 2010 at 11:43:45
is there a way to alert the user instead of calulating if over 2GB? such as a message saying unable to calucate

Report •

#11
March 31, 2010 at 11:51:08
C'mon, folks, this is not knee surgery.

==============================
@echo off & setLocal EnableDELAYedeXpansion

set B=
for /f "tokens=* delims= " %%a in ('dir/b/s/a-d c:\*.tmp') do (
set /a B+=%%~Za
)
echo.!B! bytes
set G=!B:~0,-9!
if defined G echo.!G! GB


=====================================
Helping others achieve escape felicity

M2


Report •

#12
March 31, 2010 at 11:55:56
I should probably point out it overflows AT the 2GB mark, not past it.
for /f "tokens=3" %%a in ('dir /a/s/-c c:\*.tmp ^| find /i "bytes" ^| find /i /v "Free"') do set bytes=%%a
set /a test=bytes
if not %bytes%==%test% @echo Unable to calculate.

EDIT:
Mechanix2Go: 1GB = 2 ** 30 B. I'm pretty sure you know that . . . ?


Report •

#13
March 31, 2010 at 14:05:58
We can avoid the math.

==========================
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=3 delims= " %%a in ('dir /s/-c c:\*.tmp ^| find /i "file"') do (
set B=%%a
)

set G=!B:~0,-9!
if defined G echo.!G! GB && goto :eof

set M=!B:~0,-6!
if defined M echo.!M! MB && goto :eof

echo.!B! bytes


=====================================
Helping others achieve escape felicity

M2


Report •

#14
March 31, 2010 at 14:12:33
Again, that's a conversion to neither MB nor GB. It's Binary, not Metric.

Report •

#15
March 31, 2010 at 15:16:15
Sure, but why get wrapped around the axel.

Whether KB means 1000 or 1024, probably few care.

If he wants real accuracy he can just do the DIR and get on with his life.

And the DEL.


=====================================
Helping others achieve escape felicity

M2


Report •

#16
March 31, 2010 at 20:06:39
Just for arguments sake.(actually quite fast)

Yet again, not pretty.

-----------------------------------------------------------------------------------------

Hi M2!


Report •

#17
April 1, 2010 at 01:07:34
Hi Judago,

The idea of checking the .tmp size seems pointless if you're going to do the DEL anyway.

What might be more useful is to compare the free space before and after the DEL.


=====================================
Helping others achieve escape felicity

M2


Report •

#18
April 1, 2010 at 03:03:31
Agreed, especially because some files might be locked and fail to delete.

Report •

#19
April 1, 2010 at 07:43:41
Hey guys, do I need to add some more confusion, by mentioning the fact that the size of a file, and the size a file causes to be used on a disk, can be really different ... especially with a lot of small files. Zero-byte files are fun as well, AFAIK, they occupy one allocation unit ?!

Brock : just delete the files, there should be not more than 2 Gigs in total

This is what I have on C:
Total Files Listed:
1511 File(s) 178.446.641 bytes


Report •


Ask Question