Delete python .exe's cwd

67 Views Asked by At

I'm trying to make a uninstaller tool and I'm having issues with the end of the code

This works but only deletes the .exe not the cwd

subprocess.Popen(f"WAITFOR /T 2 PAUSE 2>NUL & DEL \"{argv[0]}\" /f", shell=True, creationflags=0x00000008)

This deletes everything in the directory but not the directory itself

subprocess.Popen(f"WAITFOR /T 2 PAUSE 2>NUL & RD /Q /S \"{os.getcwd()}\"", shell=True, creationflags=0x00000008)
1

There are 1 best solutions below

0
Gregory leyda On

This works:

os.chdir("..")
subprocess.Popen(f"(WAITFOR /T 5 PAUSE 2>NUL) & (RD /Q /S \"{os.getcwd()}\\FolderToDelete\")", shell=True, creationflags=0x00000008)

Thanks! https://stackoverflow.com/users/1362735/heretolearn