Python: Difference between os.remove() and os.unlink() and which one to use?

前端 未结 2 719
萌比男神i
萌比男神i 2021-01-01 08:44

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

What\'s the difference between using os.remove() and

2条回答
  •  长情又很酷
    2021-01-01 09:02

    They are identical as described in the official Python 2.7.15 documentation.

    os.remove(path):

    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.

    Availability: Unix, Windows.

    os.unlink(path):

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

    Availability: Unix, Windows.

提交回复
热议问题