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.

Return Value

This method does not return any value.

Example

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

# !/usr/bin/python

import os, sys

# listing directories

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

# removing path

os.rmdir("mydir")

# listing directories after removing directory path

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

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

the dir is:

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

os.rmdir("mydir")

OSError: [Errno 90] Directory not empty: 'mydir'

The error is coming as 'mydir' directory is not empty. If 'mydir' is an empty directory, then this would produce

following result:

the dir is:

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

the dir is:

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

os.stat(path)

Description

The method stat() performs a stat system call on the given path.

Syntax

Following is the syntax for stat() method:

os.stat(path)

Parameters

• path -- This is the path, whose stat information is required.

Return Value

Here is the list of members of stat structure:

• st_mode: protection bits.

• st_ino: inode number.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!