28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Syntax

Following is the syntax for unlink() method:

os.unlink(path)

Parameters

• path -- This is the path, which is to be removed.

Return Value

This method does not return any value.

Example

The following example shows the usage of unlink() method.

# !/usr/bin/python

import os, sys

# listing directories

print "The dir is: %s" %os.listdir(os.getcwd())

os.unlink("aa.txt")

# listing directories after removing path

print "The dir after removal of path : %s" %os.listdir(os.getcwd())

Let us compile and run the above program, this will produce the following result:

The dir is:

[ 'a1.txt','aa.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ]

The dir after removal of path :

[ 'a1.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ]

os.utime(path, times)

Description

The method utime() sets the access and modified times of the file specified by path.

Syntax

Following is the syntax for utime() method:

os.utime(path, times)

Parameters

• path -- This is the path of the file.

• times -- This is the file access and modified time. If times is none, then the file access and modified times are

set to the current time. The parameter times consists of row in the form of (atime, mtime) i.e., (accesstime,

modifiedtime).

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!