1.

Solve : Find and delete file size?

Answer»

Hi all,

I wondered if ANYBODY could help me out.

I need to create a Quality Control bat script where it looks into folder and delete .png files IF the size is below 10kb.

Is this possible?

Cheers,

IanWhat have you got so far?
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each Files In objFolder.Files
If objFS.GetExtensionName(Files) = "png" Then
If Files.Size > 10000 Then
WScript.Echo "File " & Files.Name & " found."
End If
End If
Next
save the above as script.vbs and on command line
Code: [Select]c:\test> cscript /nologo script.vbs
Hi thanks for that, but then how do i delete those files?

Cheers,

IanThat's the beauty of VBS... so PRODUCTIVE!

@echo off
setlocal enabledelayedexpansion
for /f "delims==" %%F in ('dir /B *.png') do (
set /a fsize=%%~zF
if !fsize! LSS 10240 del "%%~dpnxF"
)


Quote from: gucci_406 on April 26, 2008, 10:48:03 AM

Hi thanks for that, but then how do i delete those files?

Cheers,

Ian
what requirements have you not stated yet?
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each Files In objFolder.Files
If objFS.GetExtensionName(Files) = "doc" Then
If Files.Size > 10000 Then
WScript.Echo "File " & Files.Name & " found."
objFS.DeleteFile(Files)
End If
End If
Next
Quote from: ghostdog74 on April 26, 2008, 10:52:41 AM
what requirements have you not stated yet?

Original post

Quote
it looks into folder and delete .png files IF the size is below 10kb.

[rolls eyes]
@dias, yes i saw that in the original post thank you. I am asking OP what other requirements he has not stated yet, besides deletion of files.Hi,

Thanks spot-on guys, thanks you your help.

Cheers

IanJust a point, 10 KB (file size) is conventionally 10 x 1024 bytes = 10240 bytes.
it would depend on how OP wants it. A file with size 10239 bytes for example will not be deleted.


Discussion

No Comment Found