Jump to content

Delete files.


Aldrinn
 Share

Recommended Posts

You want delete all files in %temp% directory ?Am i right?

If yes.

This can do:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Gui = GUICreate("Form1", 354, 135)
$Button1 = GUICtrlCreateButton("Delete", 104, 80, 129, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            RunWait("cmd.exe /c del /q " & @TempDir&"\*.*",@ScriptDir,@SW_ENABLE)
            MsgBox(64,"File on %temp% directory was deleted","Files on " & @TempDir & " " & "was deleted",3)

    EndSwitch
WEnd

EDIT: But if the current file is on @tempdir busy by another process you cannot delete it.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Hi,

this should delete all files in temp folder for every userprofile if you have appropriate rights. Also variable temp should point to %userprofile%\Local Settings\Temp (this is default.)

#include <array.au3>
#include <file.au3>
;array holding default prof and service accounts
$ardefuser [4] = ["All Users", "Default User", "LocalService", "NetworkService"]
;get variable SystemDrive
$sysdrive = EnvGet ("SystemDrive")
;get default profile folder
; if you have 64 Bit OS see helpfile RegRead to change code....
$profdir = StringReplace (RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory"), _
"%SystemDrive%", $sysdrive)
;get folders in Document and Settings and store in array
$arfolders = _FileListToArray ($profdir, "*", 2)
;Loop over array
For $i = 1 To UBound ($arfolders) - 1
    ;if folder not found in default prof and service array then delete all in Temp Folder
    If _ArraySearch ($ardefuser, $arfolders [$i]) = - 1 Then FileDelete ($profdir & "\" & $arfolders [$i] & "\Local Settings\Temp\*.*")
Next

;-))

Stefan

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...