Python os.path.ismount() Method

Python os.path.ismount() method is used to check if a given path is a mount point. A mount point is a location in the filesystem where additional filesystems are mounted.

On Unix and Linux, this is typically the root of a filesystem or a location where a new filesystem has been mounted. On Windows, drive letters and UNC paths are considered mount points.

Syntax

os.path.ismount(path)

Parameters

Name Description
path (string) The path that you want to check.

Return value

  • It returns True if the path is a mount point.
  • It returns False if the path is not a mount point.

Example 1: Checking a Mount Point on Unix/Linux

Figure of Python os.path.ismount() Method

 

 

import os

path = '/'

print(os.path.ismount(path)) 

Output

True

The root is always a mount point.

Example 2: Checking a Regular Directory

Checking a Regular Directory

import os

path = '/home/user'

print(os.path.ismount(path)) 

Output

False

It returned False unless ‘/home/user’ is a mount point.

Example 3: Checking a Drive on Windows

import os

path = 'C:\\'

print(os.path.ismount(path)) 

Output

False

It doesn’t matter if the path exists or not; os.path.ismount() checks if the path is a mount point in the context of the system’s mount layout.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.