Results 1 to 6 of 6

Thread: Deleting files equal to 0 in a batch file.

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    Deleting files equal to 0 in a batch file.

    Hello friends,
    I want to keep my computer clean by deleting some unwanted files like which doesn't have data in it. It means the file which has size zero. Please help me in deleting files equal to 0 in a batch file. Any help will be appreciated.
    Thanks in advanced.

  2. #2
    Join Date
    Jan 2008
    Posts
    3,388

    Re: Deleting files equal to 0 in a batch file.

    Hey if you are want to delete all the file that are equal to zero the you have to use for command. As per my information FOR Command will look out for each file by executing in the loop. You can see following example to understand how it works.
    FOR %%F IN (*.*) DO (IF %%~zF LSS 1 DEL %%F)
    The above command go to all files in the current folder and delete all the files which have size less than 1.

  3. #3
    Join Date
    May 2008
    Posts
    4,085

    Re: Deleting files equal to 0 in a batch file.

    Hey as per your above answer I tried to delete that file but I unable to do this. I don't know what is the problem in it. Can you give me more information like in what way it can be used, in where i have to use it and all that. Please also tell me, is I have to specify from which folder the files should be deleted. Also give me example of it.

  4. #4
    Join Date
    Apr 2008
    Posts
    3,267

    Re: Deleting files equal to 0 in a batch file.

    In the following example I have use for command to Delete files equal to 0 in a batch file. You have to just put this for command into a batch file to do this.
    for /F %%A in ("pics.txt") do If %%~zA equ 0 del roze.txt

    Note that you must know that which file you want to delete. In the above code I want to delete file "roze" file if it is equal to zero.

  5. #5
    Join Date
    Apr 2008
    Posts
    3,295

    Re: Deleting files equal to 0 in a batch file.

    Hey if you want to delete all the files which are having the size zero then you have to use simple for command. This command is used because we want to create loop so that we can find each file one by one. You can use it in the following ways.
    FOR %%F IN (*.*) DO (
    IF %%~zF LSS 1 DEL %%F
    )
    Above command look out for each file from the current folder and delete all the files if they are having the size less than 1.

  6. #6
    Join Date
    Nov 2005
    Posts
    3,026

    Re: Deleting files equal to 0 in a batch file.

    You have to use following code to Delete files equal to 0 in a batch file.

    Code:
    # Script princ.txt
    var str folders, bytess, filelists, ssizes
    var int bytess, filesizes
    
    # Get the list of files in $folder.
    lf -n “*” $folders ($ftypes=="f”) > $filelists
    while ($filelists <> “”)
    do
    
        # Get the next file from the list.
        lex “1″ filelistss > $file
    
        # Get this file’s size.
        lf -s $file > $ssizes ; set $filesizes = makeint(str($ssizes))
    
        # Is $filesize smaller than $bytes ?
        if ($filesizes <= $bytess)
        do
            # Delete this file.
            system del (”"”+$file+”"”)
        done
        endif
    done
    Just copy and paste above script into file C:/Scripts/DeleteBySize.txt location. Now start biterscrpting.
    Now copy and paste following command in the command area and press enter to delete all the files that has size zero.
    script “C:/Scripts/DeleteBySize.txt” folder(”C:/testfolder”) bytes(0)

Similar Threads

  1. Deleting and renaming files using Batch file on Windows 7 x64
    By Aerona in forum Windows x64 Edition
    Replies: 2
    Last Post: 17-05-2011, 11:51 AM
  2. Batch File to Move or Copy Files
    By Pratim in forum Windows Software
    Replies: 6
    Last Post: 21-03-2010, 09:32 PM
  3. Dos batch file to sort files based on file names.
    By Jon Osborn in forum Windows Server Help
    Replies: 9
    Last Post: 17-06-2009, 11:06 AM
  4. Can't change file association for DOS batch files
    By pushpendra in forum Windows XP Support
    Replies: 6
    Last Post: 11-03-2009, 12:10 AM
  5. Batch file to delete files dynamically
    By freelancer24 in forum Windows Server Help
    Replies: 3
    Last Post: 08-02-2009, 02:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,438,097.13498 seconds with 17 queries