[英]How do I remove a specific number of files using python (version 2.5)?
I would like to remove two files from a folder at the conclusion of my script. 我想在脚本结束时从文件夹中删除两个文件。 Do I need to create a function responsible for removing these two specific files?
我需要创建一个负责删除这两个特定文件的功能吗? I would like to know in some detail how to use os.remove (if that is what I should use) properly.
我想详细了解如何正确使用os.remove(如果那是我应该使用的)。 These two files will always be discarded at the conclusion of my script (which packages a series of files together in a zip format).
在我的脚本结束时(这一系列文件以zip格式打包在一起),这两个文件将始终被丢弃。 Thanks in advance.
提前致谢。
听起来您真正想要的是一个临时文件: http : //docs.python.org/library/tempfile.html
在脚本末尾具有“ cleanup()”函数是完全可以接受的,该函数将在文件上调用“ os.remove()”。
Just call os.remove("path/to/file")
. 只需调用
os.remove("path/to/file")
。 For example, to remove the file .emacs
, call 例如,要删除文件
.emacs
,请调用
os.remove(".emacs")
The path should be a str
that's the pathname of the file. 该路径应为
str
,即文件的路径名。 It may be relative or absolute. 它可以是相对的也可以是绝对的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.