Hi again!
Each day the user log of the system a certain registry key is exported to a reg-file. This regkey contain info for an application that all our users uses, and we want to make sure that we can restore this key when deleting the users profile in case of problem.
The last script above did what I wanted perfectly.
It always keeps at least 10 files and when exeding 10 the last is deleted first. Making sure that even if the user is away for long time, the last files are saved.
One more question though... 
Beside the regkey I also backup a certain file on the computer...
And just as above I only want to save the last 10 and only 10 files.
No problem, I thought. I took the code and inserted it once more in the script to run on another folder. But NO.
It deletes tha newest file and keeps older ones.
What I have done is to simply insert the code two times after each other in the script.. Have I missed something or done wrong?
Regards, Magnus Finbom
Code:
Go H:
CD "\egnadata\Backup\CIC"
$iLimit=10
$sResult=udfPipe('"'+%COMSPEC%+'" /C dir /a-d /o-d /b')
If @ERROR
"Could not get files. Error is:" ?
"["+@ERROR+"] "+@SERROR ?
"Extended error: " ?
$sResult[1] ?
Else
For Each $sFile In Split($sResult[0],@CRLF)
If $sFile
If $iLimit
"Will not delete file "+$sFile+@CRLF
$iLimit=$iLimit-1
Else
"Will delete file "+$sFile+@CRLF
Del $sFile
EndIf
EndIf
Next
EndIf
Go H:
CD "\egnadata\Backup\Outlook"
$iLimit=10
$sResult=udfPipe('"'+%COMSPEC%+'" /C dir /a-d /o-d /b')
If @ERROR
"Could not get files. Error is:" ?
"["+@ERROR+"] "+@SERROR ?
"Extended error: " ?
$sResult[1] ?
Else
For Each $sFile In Split($sResult[0],@CRLF)
If $sFile
If $iLimit
"Will not delete file "+$sFile+@CRLF
$iLimit=$iLimit-1
Else
"Will delete file "+$sFile+@CRLF
Del $sFile
EndIf
EndIf
Next
EndIf
; Execute a command and return output and error streams
; This code adapted from Chris S. WshPipe() http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=8257
Function udfPipe($sCommand)
Dim $oExec
ReDim $udfPipe[2]
$oExec = CreateObject("WScript.Shell").Exec($sCommand)
If NOT VarType($oExec)=9 $udfPipe[1]=@SERROR Exit @ERROR EndIf
$udfPipe[0] = $oExec.StdOut.ReadAll
$udfPipe[1] = $oExec.StdErr.ReadAll
Exit $oExec.ExitCode
EndFunction ;}}}