Sign in to follow this  
Followers 0
au3scr

Temp delete

10 posts in this topic

Hi how to do script that deletes all files in temp dir?

is there any command to delete all files?

there are also some files that you cant delete (prodected by system) so script should skip these.


Share this post


Link to post
Share on other sites



DirRemove(@TempDir & "\", 1)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

--

Edited by AL3X

Share this post


Link to post
Share on other sites

Yep.

Share this post


Link to post
Share on other sites

Wont this remove the entire folder of temporary files ? :S

Which is regenerated when it is rewritten too, but this time when it is rewritten, it is empty :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

--

Edited by AL3X

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Untested:

#Include <File.au3>
$dir = @TempDir
$files = _FileListToArray($dir)
For $i = 1 to UBound($files) - 1
FileDelete($files[$i])
Next
Edited by Senton-Bomb

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

--

Edited by AL3X

Share this post


Link to post
Share on other sites

thank you


Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Perhaps this are files which are still in use of some programs or processes !

It's not recommended to delete them while the process take use of the files.

i.e. my Firewall uses some temporary files in my Temp folder and I don't think that it would be a gain if I force to delete it, isn' t it !?

Maybe the other files without importance you can't delete, are set to read only, so test to set the attributes to writable ...

Run before the DirRemove a FileSetAttrib(.., .., 1) with the '1' parameter at the end.

For subfolders you have to create a loop ...

Greetz

Greenhorn

Edit: Look at here ...

http://www.autoitscript.com/forum/index.ph...temporary+files

; Author:    MadBoy
#Include <File.au3>

;_DirRemoveContents(@UserProfileDir & '\Local Settings\Temporary Internet Files\Content.IE5')
;_DirRemoveContents(@TempDir)

Func _DirRemoveContents($folder)
    Local $list_of_contents, $status
    $list_of_contents = _FileListToArray($folder)
    If IsArray($list_of_contents) Then
        If StringRight($folder, 1) <> "\"  Then $folder = $folder & "\"
        If @error = 1 Then Return 1 ; No Files\Folders Found
        For $a = 1 To $list_of_contents[0]
            FileSetAttrib($folder & "\" & $list_of_contents[$a], "-RASH")
            If StringInStr(FileGetAttrib($folder & $list_of_contents[$a]), "D") Then
                $status = DirRemove($folder & $list_of_contents[$a], 1)
            Else
                $status = FileDelete($folder & $list_of_contents[$a])
            EndIf
        Next
    Else
        Return 2 ; Directory doesn't exists
    EndIf
EndFunc   ;==>_DirRemoveContents

Edited by Greenhorn

Share this post


Link to post
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
Sign in to follow this  
Followers 0