Members
  • Total Members: 14176
  • Latest: toxxxa
Stats
  • Total Posts: 42955
  • Total Topics: 16151
  • Online Today: 4651
  • 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 2934 times)

0 Members and 1 Guest are viewing this topic.

devnullius

  • SCF VIP Member
  • *****
  • Posts: 3614
  • KARMA: 157
  • Gender: Female
    • SCForum.info
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 https://stackoverflow.com/a/48162127/2792969 for a full discussion

Code: [Select]
'FROM https://stackoverflow.com/questions/48159497/windows-bat-script-to-get-directory-size-if-over-n-gb-then-delete-oldest-files-t
'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
            .Open

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

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

Peace!
More information about bitcoin, altcoin & crypto in general? GO TO  j.gs/7385484/btc

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 http://goo.gl/n1ONa9

Samker's Computer Forum - SCforum.info


RuskinF

  • 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 - SCforum.info


 

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:
Verification:
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):www.scforum.info:

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

Terms of Use | Privacy Policy | Advertising