Sign in to follow this  
Followers 0
Caaio

Trying to erase TMP files

7 posts in this topic

Dear guys,

i`m trying to make a script that erase Temp files, but i didn`t have success in all tests that i made:

I`m trying with

#include <Process.au3>

;apaga TMP

_RunDOS (@TempDir & "del *.* /s /q")

The script is executed without error message, but the temp files still appearing.What`s wrong in my script?!

Thans who can help me.

Regards.

Share this post


Link to post
Share on other sites



Sorry guys, but i`m new in AutoIt scripts. And i will thank you if you can give me some tips to do this simple script!

thanks again.

Regards.

Share this post


Link to post
Share on other sites

instead of using dos why not Autoit

_DeleteFiles(@TempDir, "*.*", 1)

Func _DeleteFiles($sPath, $sFilter, $iRemDir = 0)
    Local $hSearch, $sFile
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then
        If $iRemDir = 1 Then DirRemove($sPath)
        SetError(1)
        Return 0
    EndIf
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error = 1 Then
            If $iRemDir = 1 Then DirRemove($sPath, 0)
            SetError(0)
            Return 1
        EndIf
        If $sFile = ".." Or $sFile = "." Then ContinueLoop
        $sFile = $sPath & "\" & $sFile
        If StringInStr(FileGetAttrib($sFile), "D") Then
            _DeleteFiles($sFile, "*", 1)
            ContinueLoop
        EndIf
        FileDelete($sFile)
    WEnd
EndFunc

also check :

http://www.autoitscript.com/forum/index.php?showtopic=27603

http://www.autoitscript.com/forum/index.php?showtopic=45933

Share this post


Link to post
Share on other sites

Thanks for the support mrbond007. I copy your code and it`s worked fine. But I would like to understand what your script is doing, i start to study it but i have some question about that.

As I said, i`m new user and i would like to learn more to how to program on it.

I would like to understand this:

$hSearch = FileFindFirstFile($sPath & "\" & $sFilter)

You didn`t declareted the $sPath and $sFilter. So, how AutoIT will know wich files will search?

Thanks fow who can help me.

Regards.

Share this post


Link to post
Share on other sites

If $sFile = ".." Or $sFile = "." Then ContinueLoop
That is line is not required. FileFindNextFile() has not returned ".." or "." for a long time. They were removed many versions ago. Just remove the line from the code as it does nothing useful.

:whistle:

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