Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Find and delete file size  (Read 3630 times)

0 Members and 1 Guest are viewing this topic.

gucci_406

    Topic Starter


    Greenhorn

    Find and delete file size
    « on: April 26, 2008, 08:56:14 AM »
    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,

    Ian
    « Last Edit: April 26, 2008, 09:07:01 AM by gucci_406 »

    Dias de verano

    • Guest
    Re: Find and delete file size
    « Reply #1 on: April 26, 2008, 10:01:53 AM »
    What have you got so far?

    ghostdog74



      Specialist

      Thanked: 27
      Re: Find and delete file size
      « Reply #2 on: April 26, 2008, 10:20:28 AM »
      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

      gucci_406

        Topic Starter


        Greenhorn

        Re: Find and delete file size
        « Reply #3 on: April 26, 2008, 10:48:03 AM »
        Hi thanks for that, but then how do i delete those files?

        Cheers,

        Ian

        Dias de verano

        • Guest
        Re: Find and delete file size
        « Reply #4 on: April 26, 2008, 10:49:26 AM »
        That'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"
             )


        « Last Edit: April 26, 2008, 11:11:37 AM by Dias de verano »

        ghostdog74



          Specialist

          Thanked: 27
          Re: Find and delete file size
          « Reply #5 on: April 26, 2008, 10:52:41 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

          Dias de verano

          • Guest
          Re: Find and delete file size
          « Reply #6 on: April 26, 2008, 10:57:26 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]

          ghostdog74



            Specialist

            Thanked: 27
            Re: Find and delete file size
            « Reply #7 on: April 26, 2008, 11:02:00 AM »
            @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.

            gucci_406

              Topic Starter


              Greenhorn

              Re: Find and delete file size
              « Reply #8 on: April 26, 2008, 11:07:42 AM »
              Hi,

              Thanks spot-on guys, thanks you your help.

              Cheers

              Ian

              Dias de verano

              • Guest
              Re: Find and delete file size
              « Reply #9 on: April 26, 2008, 11:10:58 AM »
              Just a point, 10 KB (file size) is conventionally 10 x 1024 bytes = 10240 bytes.

              ghostdog74



                Specialist

                Thanked: 27
                Re: Find and delete file size
                « Reply #10 on: April 26, 2008, 08:00:40 PM »
                it would depend on how OP wants it. A file with size 10239 bytes for example will not be deleted.