Python:os.remove()和os.unlink()之间的区别以及使用哪一个? [英] Python: Difference between os.remove() and os.unlink() and which one to use?

查看:1095
本文介绍了Python:os.remove()和os.unlink()之间的区别以及使用哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹中有很多文件。我要在处理完每个文件后删除它们。

I have a number of files in a folder. I want to delete each file once it has been processed.

使用 os.remove()有什么区别和 os.unlink ?哪种方法最适合我的情况?

What's the difference between using os.remove() and os.unlink? Which method is ideal for my scenario?

推荐答案

它们与 Python 2.7.15官方文档

操作系统。删除路径):


删除(删除)文件 path 。如果 path 是目录,则
引发OSError ;请参阅下面的 rmdir()以删除目录。 与$ a
相同,它与 unlink()函数
(如下所述)。在Windows上,
尝试删除正在使用的文件会引发
异常;在Unix上,目录条目已删除,但是分配给文件的存储
在原始文件
不再使用之前不可用。

Remove (delete) the file path. If path is a directory, OSError is raised; see rmdir() below to remove a directory. This is identical to the unlink() function documented below. On Windows, attempting to remove a file that is in use causes an exception to be raised; on Unix, the directory entry is removed but the storage allocated to the file is not made available until the original file is no longer in use.

可用性:Unix,Windows。

Availability: Unix, Windows.

操作系统。取消链接路径):


删除(删除)文件 path 此功能与 remove()相同;
unlink()名称是其传统的Unix名称。

Remove (delete) the file path. This is the same function as remove(); the unlink() name is its traditional Unix name.

可用性:Unix,Windows。

Availability: Unix, Windows.

这篇关于Python:os.remove()和os.unlink()之间的区别以及使用哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆