Python | os.DirEntry.inode() method
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.scandir()
method of os module yields os.DirEntry
objects corresponding to the entries in the directory given by specified path. os.DirEntry
object has various attributes and method which is used to expose the file path and other file attributes of the directory entry.
inode()
method on os.DirEntry
object is used to get the inode number of a entry.
Note: os.DirEntry
objects are intended to be used and thrown away after iteration as attributes and methods of the object cache their values and never refetch the values again. If the metadata of the file has been changed or if a long time has elapsed since calling os.scandir() method. we will not get up-to-date information.
Syntax: inode()
Parameter: No parameter is required
Return type: This method returns an integer value which represents the inode number of the entry.
Code: Use of os.DirEntry.inode() method
import os
path = os.getcwd()
print ( "Directory entry name and their inode number" )
with os.scandir(path) as itr:
for entry in itr :
if not entry.name.startswith( '.' ) :
print (entry.name, " :" , entry.inode())
|
Output:
Directory entry name and their inode number
Public : 786500
Desktop : 786497
R : 1969824
foo.txt : 801099
graph.cpp : 801237
tree.cpp : 801364
Pictures : 786503
abc.py : 801140
file.txt : 801366
Videos : 786504
images : 1969766
Downloads : 786498
geeksforgeeks : 2097180
Music : 801428
Documents : 786501
References: https://docs.python.org/3/library/os.html#os.DirEntry.inode
Last Updated :
26 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...