How to remove A_ScriptDir after ExitApp Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
newbieforever
Posts: 444
Joined: 24 Aug 2016, 03:34

How to remove A_ScriptDir after ExitApp

06 Apr 2019, 03:02

Hi!

My demo constellation:
- The script directory MyDir contains the script file RemDir.ahk and the interpreter AutoHotkey.exe.
- RemDir.ahk should remove the complete script directory after ExitApp.
- But it deletes only the files contained in MyDir, not the directory itself.
Why is this so? How to do it?

Code: Select all

#Persistent

F9::
  Cmd = %ComSpec% /c ping localhost -n 1 > nul & rd /s /q "%A_ScriptDir%"
  Run, %Cmd%, , Hide
  ExitApp
Return
(edited)
Kobaltauge
Posts: 239
Joined: 09 Mar 2019, 01:52
GitHub: MassimoCastell
Location: Germany
Contact:

Re: How to remove A_ScriptDir after ExitApp

06 Apr 2019, 04:40

The command can't delete a folder that is in usage. You started AutoHotkey.exe and the script from the folder, therefore it's in usage.
To delete the folder the process shouldn't run anymore. This is impossible with your way.
newbieforever
Posts: 444
Joined: 24 Aug 2016, 03:34

Re: How to remove A_ScriptDir after ExitApp

06 Apr 2019, 04:58

@Kobaltauge:

I think, your answer is (at least partially) incorrect. The ping command is used for a time delay so that the rd command is executed after the script is terminated. Otherwise it wouldn't be possible even to delete AutoHotkey.exe! But the demo script deletes the interpreter, so it is clear that the process is terminated.
newbieforever
Posts: 444
Joined: 24 Aug 2016, 03:34

Re: How to remove A_ScriptDir after ExitApp  Topic is solved

06 Apr 2019, 05:03

Okay, I found out the reason: It's just a DOS issue...the directory is not removed because it is the current directory for the DOS commands.

This seems to work:

Code: Select all

#Persistent

F9::
  Cmd = %ComSpec% /c cd .. & ping localhost -n 1 > nul & rd /s /q "%A_ScriptDir%"          ; cd ..   !!!
  Run, %Cmd%, , Hide
  ExitApp
Return
Kobaltauge
Posts: 239
Joined: 09 Mar 2019, 01:52
GitHub: MassimoCastell
Location: Germany
Contact:

Re: How to remove A_ScriptDir after ExitApp

07 Apr 2019, 13:09

newbieforever wrote:
06 Apr 2019, 04:58
Oh, OK. Thank you. I didn't test it with the ".exe" in the folder.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, barbaque, Bing [Bot], boiler, c7aesa7r, dagiccross, Flipeador, Ian and 374 guests