强制删除文件。 Python、Windows
我正在研究重置按钮。该按钮应该清除文本小部件中生成的文本并删除数据写入的文件。清除文本小部件可以,但我在删除文件时遇到问题。
当我尝试从 Windows 中删除它时,它说它在 Python 中仍然打开。因此,我先从代码中关闭它,然后尝试删除它,但没有成功。
我已经对另一个按钮进行了编程,使其不会覆盖文件。所以,我不能只删除文件中已经写入的数据。
有什么办法可以强制删除该文件吗?
我正在使用Python 2.6.6。
这是我在重置按钮上的代码:
def reset_it(self):
self.run.update() # run is the other button, I have to stop it's processing!
self.Outputlines.update() # Forcing the TextWidget to update.
self.Outputlines.config(state=NORMAL)
self.Outputlines.delete(1.0, END) # Clearing everything from the TextWidget.
self.Outputlines.config(state=DISABLED)
self.run.wait_variable() # Stopping the run button.
self.infile.close() # Closing the file.
os.remove(self.filename.get()) # Code to delete the file.
I am working on a Reset button. The button is supposed to clear the text that is generated in a Text Widget and delete the file that the data was being written to. Clearing the Text Widget works, but I am having problems deleting the file.
When I try to delete it from windows, it says that it is still open in Python. So, I closed it from my code first, and then tried to delete it but didn't work.
I have programmed the other button so that it doesn't override files. So, I can't just delete the data that is already written in the file.
Is there any way that I can force the deletion of that file??
I am using Python 2.6.6.
This is my code on the reset button:
def reset_it(self):
self.run.update() # run is the other button, I have to stop it's processing!
self.Outputlines.update() # Forcing the TextWidget to update.
self.Outputlines.config(state=NORMAL)
self.Outputlines.delete(1.0, END) # Clearing everything from the TextWidget.
self.Outputlines.config(state=DISABLED)
self.run.wait_variable() # Stopping the run button.
self.infile.close() # Closing the file.
os.remove(self.filename.get()) # Code to delete the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论