windows python脚本遍历目录以删除文件夹,重新启动PC并继续脚本的下一行?

发布于 2024-09-18 23:13:03 字数 184 浏览 0 评论 0原文

我想删除错误安装的程序并重新安装。我可以使用 subprocess.Popen 调用 msiexe 来删除该程序,并以相同的方式安装新程序,但只能使用两个独立的脚本。但我还需要删除 C:\Programs 文件以及 C:\Doc& 中的一些文件夹。设置。我如何遍历目录结构并删除文件夹?另外,如何在从下一行重新启动电脑后继续执行脚本以安装新程序。

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 can i continue the script after restart the PC from the next line to install the new program.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2024-09-25 23:13:03

简而言之,这就是您需要做的事情。

您可以使用 os< 中的 remove()rmdir()removdirs() 方法删除文件和文件夹/code> 模块(假设您的用户/程序具有管理权限)。

要重新启动脚本,您首先需要向其添加一些命令行参数处理,以允许它被告知是从头开始还是从另一点继续。

要使脚本在重新启动后运行,您需要在 Windows 注册表中设置一个值。我相信它们存储在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce 键下。您可以在其中添加一个字符串值(类型REG_SZ),其中包含一个调用脚本的命令行,并向其传递适当的命令行参数,该参数将告诉它继续并重新安装程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文