Jump to content
Sign in to follow this  
liten

Delte directory

Recommended Posts

liten

I want a file to delete its self after its done running would i just do this with DirRemove?


My UDF:Freeze.au3-Freeze values like CE, ML, ETC[i][/i][u][/u]

Share this post


Link to post
Share on other sites
herewasplato

I want a file to delete its self ...

Is this "file" an AutoIt script? If yes, this you might want to consider this UDF from the FAQ:
Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '"' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & 'scratch.bat'
    FileWrite(@TempDir & "scratch.bat", $sCmdFile)
    Run(@TempDir & "scratch.bat", @TempDir, @SW_HIDE)
EndFunc;==>_SelfDelete

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
martin

Is this "file" an AutoIt script? If yes, this you might want to consider this UDF from the FAQ:

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '"' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & 'scratch.bat'
    FileWrite(@TempDir & "scratch.bat", $sCmdFile)
    Run(@TempDir & "scratch.bat", @TempDir, @SW_HIDE)
EndFunc;==>_SelfDelete
Shouldn't

$sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _

be

$sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _

?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
liten

and i dont understand how i am supposr to plug that in , i menan wat do i replace, @dir??


My UDF:Freeze.au3-Freeze values like CE, ML, ETC[i][/i][u][/u]

Share this post


Link to post
Share on other sites
herewasplato

Shouldn't

$sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _

be

$sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _

?

Yep - It has been that way for a long time and is in SciTE4AutoIt3 :-)

http://www.autoitscript.com/forum/index.ph...st&p=129058


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

and i dont understand how i am supposr to plug that in , i menan wat do i replace, @dir??

maybe

;your code here

Func OnAutoItExit()
    _SelfDelete(5) ; delay in seconds
EndFunc   ;==>OnAutoItExit


Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc   ;==>_SelfDelete

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Jos

Yep - It has been that way for a long time and is in SciTE4AutoIt3 :-)

http://www.autoitscript.com/forum/index.ph...st&p=129058

Yea, that has been in there for quite a while now.

It will be fixed in the next release.

Thanks

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Jos

Why not use the -w parameter to make it timeout for the milliseconds we need ?

http://www.robvanderwoude.com/wait.php

-w only does something for timeout. 127.0.0.1 gives a response so there is no timeout condition?

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Inverted

Right, well, then it needs a non-existent IP like in that link I edited later.

PING 1.1.1.1 -n 1 -w 60000 >NUL

Now that I think about it, it's not really important for the purposes of this thread.

Edited by Inverted

Share this post


Link to post
Share on other sites
KaFu

and i dont understand how i am supposr to plug that in , i menan wat do i replace, @dir??

You're not clear enough about what you want to accomplish. In the title you say delete dir, in the post that the exe should delete itself. So... should the exe delete itself after running, and which dir do you want to remove? For dir removal there is the function DirRemove ( "path" [, recurse] ), set recurse = 1 to delete all subdirectories too...

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  

×