silver217, I am not debugging that code - it is incomplete and I hate debugging recursive calls to FileFindFirst/NextFile. Please read the Recursion tutorial in the Wiki to see why - and to find out a better way to do it. Here is a function I just threw together using my RecFileListToArray UDF (look in my sig for the link). I have tested it a few times and it seems to work fine: #include <RecfileListToArray.au3>
#include <Array.au3>
; Set the root path
$sRoot = "N:Sizer"
; Get a list of files including in subdirs with full path
$aFileList = _RecFileListToArray($sRoot, "*", 1, 1, 0, 2)
; Now create an array of the filetimes and fill it
Global $aTimes[$aFileList[0] + 1] = [$aFileList[0]]
For $i = 1 To $aFileList[0]
$aTimes[$i] = Number(FileGetTime($aFileList[$i], 0, 1))
Next
; Just for testing
_ArrayDisplay($aFileList, "Start")
_ArrayDisplay($aTimes, "Start")
; This is the folder size at the start
MsgBox(0, "Initial Size", DirGetSize($sRoot))
; Set a suitable size here
While DirGetSize($sRoot) > 20000000
; Reset the initial values
$iOldest = 99999999999999
$sOldest = ""
$iIndex = 0
; Now go through the times to find the oldest
For $i = 1 To $aTimes[0]
If $aTimes[$i] < $iOldest Then
$iOldest = $aTimes[$i]
$sOldest = $aFileList[$i]
$iIndex = $i
EndIf
Next
; And delete the file
FileDelete($sOldest)
; Make sure it has gone
Do
Sleep(10)
Until Not FileExists($sOldest)
; And remove it from the arrays
_ArrayDelete($aFileList, $iIndex)
$aFileList[0] -= 1
_ArrayDelete($aTimes, $iIndex)
$aTimes[0] -= 1
; Just to check
_ArrayDisplay($aFileList, "In loop")
WEnd
; And this is the folder size at the end
MsgBox(0, "Final Size", DirGetSize($sRoot))It should not be too hard to amend it to fit your script, but do come back if you run into problems. M23