Delete Specific File Size using CMD prompt


  1. Posts : 21
    Windows 7 Professional 64-bit SP1
       #1

    Delete Specific File Size using CMD prompt


    Hi just want to ask a small favor if there's a way i can delete certain files using command prompt base on their file size. i uploaded the screenshot of the file that i know it's a virus and they have the same size 798kb. it is possible to delete this file using command prompt?

    thanks and advance guys!


      My Computer


  2. Posts : 1,210
    Windows 7 Ultimate x64 (XP, 98SE, 95, 3.11, DOS 7.10 on VM) + Ubuntu 10.04 LTS Lucid Lynx
       #2

    I guess this is what you need. This code should be in a batch file (put the code in a text file with the extension as .bat) and run it. I've added comments for the code.

    Code:
    @echo off
    
    rem Select all files recursively from the current folder
    for /r %%x in (*.*) do (
    rem Check if the file size is the one you want (this must be in bytes, take the "Size" from the file properties, not "Size on disk")
        if %%~zx == 542208 (
    rem Delete the file, if it matches the size you want to delete
            del "%%x"
    rem Show a message
            @echo Deleted %%x, Size %%~zx
        )
    )
    Hope this is what you want. I have also attached the batch script (make sure you change the size to what you want). Also if you want to delete files of a specific type, change the file filter (*.*) in the "for" statement.
    Attached Thumbnails Attached Thumbnails Delete Specific File Size using CMD prompt-size.png   Delete Specific File Size using CMD prompt-del.png  
    Delete Specific File Size using CMD prompt Attached Files
    Last edited by gladson1976; 15 Mar 2016 at 01:01.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 08:33.
Find Us