开发者

windows python script to traverse directory to remove folders, restart PC and continue the next line of the script?

开发者 https://www.devze.com 2023-01-16 00:39 出处:网络
I want to remove a incorrectly installed program and reinstall it. I can remove the program with subprocess.Popen calling the msiexe on it and install new program the same way BUT ONLY with two indepe

I want to remove a incorrectly installed program and reinstall it. I can remove the program with subprocess.Popen calling the msiexe on it and install new program the same way BUT ONLY with two independent scripts. But i also need to remove some folders in C:\Programs files and also in C:\Doc& Settings. How can i traverse through the directory structure and remove the folders?Also how 开发者_JAVA技巧can i continue the script after restart the PC from the next line to install the new program.


In a nutshell, here's what you'll need to do.

You can delete the files and folders by using the remove() and rmdir() or removedirs() methods in the os module (assuming your user/program has administrative rights).

To restart your script you will first need to add some command line argument handling to it that allows it to be told whether to start from the beginning or continue from the other point.

To get the script to run after restart, you'll need to set a value in the Windows registry. I believe they're stored under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceand HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOncekeys. There you can add a string value (type REG_SZ) which contains a command line to invoke your script and pass it the appropriate command line argument(s) which will tell it to continue and re-install the program.

0

精彩评论

暂无评论...
验证码 换一张
取 消