this-is-me Posted May 10, 2004 Share Posted May 10, 2004 I have made a script that I am having some trouble on. Here is what I want to do: XP: Delete temporary files from each user account Delete temporary internet files from each user account excluding .txt files in case of cookies 98: Delete temporary files Delete temporary internet files excluding .txt files in case of cookies I do not want to delete the top level folder itself, just the files and folders under it. In the meantime, I also need to have a running tab on how many files are being deleted. I have created the following script that does what I want it to do, but it uses a lot of system resources because of the looping and speed of deletion: expandcollapse popup$begintime = TimerStart() $tmptotal = 0 $drives = DriveGetDrive("fixed") If NOT @error Then for $i = 1 to $drives[0] if DriveStatus($drives[$i] & "\") = "READY" then if FileExists($drives[$i] & "\Documents And Settings\") then $users = FileFindFirstFile($drives[$i] & "\Documents And Settings\*.*") If $users <> -1 Then while 1 $cuser = FileFindNextFile($users) If @error Then ExitLoop if $cuser = "All Users" or $cuser = "Default User" or $cuser = "LocalService" or $cuser = "NetworkService" or $cuser = "." or $cuser = ".." then ContinueLoop delcont($drives[$i] & "\Documents And Settings\" & $cuser & "\Local Settings\Temp", "", 0) delcont($drives[$i] & "\Documents And Settings\" & $cuser & "\Local Settings\Temporary Internet Files\Content.IE5", ".txt", 0) wend endif FileClose($users) endif delcont($drives[$i] & "\Windows\Temp", "", 0) delcont($drives[$i] & "\Windows\Temporary Internet Files\Content.IE5", ".txt", 0) endif next endif ToolTip("") $min = 0 $sec = Round(TimerStop($begintime)/1000) if $sec > 60 then $min = Int($sec/60) $sec = $sec - ($min*60) $totaltime = $min & " Minutes and " & $sec & " Seconds." msgbox(0,"", "Deleted a total of " & $tmptotal & " temporary files in " & $totaltime) func delcont($folder, $filespec, $dlfldr) if not FileExists($folder) then return if StringInStr(FileGetAttrib($folder), "D") then $cur = FileFindFirstFile($folder & "\*") While 1 $curfile = FileFindNextFile($cur) If @error Then ExitLoop if $curfile = "." or $curfile = ".." then ContinueLoop if StringInStr(FileGetAttrib($folder & "\" & $curfile), "D") then delcont($folder & "\" & $curfile, $filespec, 1) else if $filespec = "" then mydel($folder & "\" & $curfile) else if not StringInStr($curfile, $filespec) then mydel($folder & "\" & $curfile) endif endif endif WEnd FileClose($cur) if $dlfldr = 1 then rmifempty($folder) endif endfunc func mydel($fl) if StringInStr(FileGetAttrib($fl), "R") then FileSetAttrib($fl, "-R") $tst = FileDelete($fl) if $tst <> 0 then $tmptotal = $tmptotal + 1 ToolTip("Files Deleted: " & $tmptotal); & @LF & "Current File: " & $fl endfunc func rmifempty($fl) $fld = FileFindFirstFile($fl & "\*") While 1 $fldr = FileFindNextFile($fld) If @error Then ExitLoop if $fldr = "." or $fldr = ".." then ContinueLoop return WEnd FileClose($fld) DirRemove($fl) endfunc Is there anything I can do to make this run faster without losing the features I need? Who else would I be? Link to comment Share on other sites More sharing options...
Nutster Posted May 10, 2004 Share Posted May 10, 2004 What about calling the Windows Disk Cleanup program? David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... Link to comment Share on other sites More sharing options...
this-is-me Posted May 10, 2004 Author Share Posted May 10, 2004 (edited) I really don't like windows disk cleanup because it does not tell me how many files are deleted and takes too long in xp to calculate how much is saved using the "compress old files" option. My main three considerations are speed, resources and file count. Edited May 10, 2004 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
ezzetabi Posted May 11, 2004 Share Posted May 11, 2004 What about calling the Windows Disk Cleanup program?Thats a really bad advice...Here a good one http://www.skali.com/index.php?ac=1206&ch=15&pg=136This is the best file cleaner... Link to comment Share on other sites More sharing options...
this-is-me Posted May 12, 2004 Author Share Posted May 12, 2004 I appreciate the help, but I want an AutoIt-only solution that gives me a total number of files deleted. Therefore, I need to know what needs to be done to get this to use less resources. Who else would I be? Link to comment Share on other sites More sharing options...
ezzetabi Posted May 12, 2004 Share Posted May 12, 2004 Try puting some Sleep(10) in loops... Even a 1/100 of sec can help reduce the use of the CPU drastically. You may even add an options that set how much CPU use... Like: Max - No Sleep() Normal - Sleep(10) Low - Sleep(100) Link to comment Share on other sites More sharing options...
this-is-me Posted May 12, 2004 Author Share Posted May 12, 2004 I will try that, but doesn't that only slow down the time to complete? Who else would I be? Link to comment Share on other sites More sharing options...
ezzetabi Posted May 13, 2004 Share Posted May 13, 2004 Of course it slows down the process, but also it is impossible to use less resource and also go at the same speed, don't you think? In Sleep() moment the CPU will not work on your script and so it will use resource for others process that need, so your script will slowdown the computer less. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now