• Total Posts: 43151
  • Total Topics: 16308
  • Online Today: 6172
  • Online Ever: 51419
  • (01. January 2010., 10:27:49)

Author Topic: Windows tool to remove the oldest files once a folder size exceeds ?GB  (Read 3043 times)

0 Members and 2 Guests are viewing this topic.


  • SCF VIP Member
  • *****
  • Posts: 3614
  • KARMA: 157
  • Gender: Female
I had to  google a bit before I found a bat or vbs or ps1 or exe tool that could do the following:

Check the size of a folder, once that folder exceeds a maximum size, start removing the oldest files until the folder's quotum is below its maximum set size.

The solution I found was a VBS script. Copy pastas below :)

SOURCE: Go to for a full discussion

Code: [Select]
'2^30*1 means 1GB and 2^30*8 means 8GB. Below, you need to change that multiplier twice and both (logically) should be the same value
'to set your folder's maximum size in GB
'And of course you need to change the folder name to match your folder

Set fso = CreateObject("Scripting.FileSystemObject")
Set F = fso.GetFolder("C:\Users\User\Pictures\Microsoft")

If F.size > 2^30*4 Then
            'Comments on a stupid editor that can't handle tabs
            'Creating an in memory disconnected recordset to sort files by date
        Set rs = CreateObject("ADODB.Recordset")
        With rs
            .Fields.Append "Date", 7
            .Fields.Append "Txt", 201, 5000

            For Each Thing in f.files
                .Fields("Date").value = thing.datelastmodified
                .Fields("Txt").value = thing.path
            .Sort = "Date Desc"
            Do While not .EOF
                fso.deletefile  .Fields("Txt").Value
                If f.size < 2^30*4 then Exit Do
        End With
End If

Run it with Task Scheduler when your PC is idle (or set it on a fixed schedule). Enjoy!!

More information about bitcoin, altcoin & crypto in general? GO TO

Cuisvis hominis est errare, nullius nisi insipientis in errore persevare... So why not get the real SCForum employees to help YOUR troubled computer!!! SCF Remote PC Assist

Samker's Computer Forum -


  • SCF Member
  • **
  • Posts: 64
  • KARMA: 5
  • Gender: Male
Before we look at several Windows files and folders that you can safely remove, you should know that manually deleting them isn’t the best way to go about it.

Aside from wasting time doing this yourself when you could automate the process, it’s safer to let the Disk Cleanup tool do these cleanings for you. This avoids accidentally deleting files that you need or messing with the wrong folders.

The Windows Disk Cleanup tool helps you reclaim disk space on your computer and is simple to use. You can open it by searching for Disk Cleanup in the Start Menu. Let it scan, and you’ll see several categories of files you can erase. For more options, choose Clean up system files to gain administrator permissions.

Samker's Computer Forum -


With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name: Email:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
Second Anti-Bot trap, type or simply copy-paste below (only the red letters)

Enter your email address to receive daily email with ' - Samker's Computer Forum' newest content:

Terms of Use | Privacy Policy | Advertising