1.

Solve : Deleting files equal to 1KB in a batch file?

Answer»

How to create a script to delete files (ej.: *.xml or *.html) equal to 1KB in batch file?Did you mean files whose size is exactly 1024 bytes? Not more? Not less?

I refer to files that are 1KB, may be more or less bytes. I do not know much about the subject of bytes.
thanks for you reply...1024 bytes = 1 kilobyte = 1 KB.

I ask again. Do you want to only delete files that are 1 KB in size? (Did you mean size?)
only the files of size 1KBCode: [Select]@echo off
REM example
set mask=*.xml
for /f "delims=" %%A in ('dir /b %mask%') do if %%~zA equ 1024 del "%%~dpnxA"
D:\Temp>dir
Volume in drive D has no label.
Volume Serial Number is 1C5A-305C

Directory of D:\Temp

12/07/2010 17:07 .
12/07/2010 17:07 ..
12/07/2010 11:45 2,873 1.xml
12/07/2010 11:46 25,857 10.xml
09/13/2010 13:15 115 2.xml
12/07/2010 11:45 2,873 3.xml
09/13/2010 13:15 115 4.xml
12/07/2010 11:45 2,873 5.xml
09/13/2010 13:15 115 6.xml
12/07/2010 11:45 2,873 7.xml
09/13/2010 13:15 115 8.xml
12/07/2010 11:45 2,873 9.xml
12/07/2010 17:07 93 del.bat
11 File(s) 40,775 bytes
2 Dir(s) 14,180,757,504 bytes free

D:\Temp>del.bat

D:\Temp>set mask=*.xml

D:\Temp>for /F "delims=" %A in ('dir /b *.xml') do if %~zA EQU 1024 del "%~dpnxA"
File Not Found

D:\Temp>

Files 2.xml, 4.xml, 6.xml, 8.xml are files of 1KB to windows.Quote from: mdibarra on December 07, 2010, 01:15:05 PM

Files 2.xml, 4.xml, 6.xml, 8.xml are files of 1KB to windows.

In the DETAILS view, Windows EXPLORER rounds file SIZES, roughly to the nearest 1 KB. Files under 1024 bytes are shown as "1 KB". The file 2.xml is in fact 115 bytes in size as you can see. so are 4, 6 and 8.xml.


Quote
File Not Found

Is the batch file in the same folder?


Yes, the batch file name is del.batQuote from: mdibarra on December 07, 2010, 01:40:20 PM
Yes, the batch file name is del.bat

And the .xml files are in the same folder? Are they hidden, system or read-only? What HAPPENS if you run this batch in that folder?


Code: [Select]@echo off
echo.
echo This file is %~dpnx0
echo.
echo 1
for /f "delims=" %%A in ('dir /b *.*') do echo File %%A %%~zA bytes
echo.
echo 2
echo.
for /f "delims=" %%A in ('dir /b *.xml') do echo File %%A
echo.
echo Finished


Discussion

No Comment Found