0

I'm attempting to write a program that retrieves the file name, absolute path, etc., from a file path. Is there a module I can use in order to do that? Here's a snippet of my code

import os

filepath = "home/Documents/example.py"

print("File Name: " + os.path.basename(filepath))
print("File Path: " + os.path.abspath(filepath))
print("inode: " + os.DirEntry.inode(filepath))

I looked up a few sites and videos for this but haven't found a satisfying answer. The error I get from trying that is

TypeError: descriptor 'inode' for 'posix.DirEntry' objects doesn't apply to a 'str' object
AerialSong
  • 49
  • 1
  • 7
  • Does this answer your question? [How to get an absolute file path in Python](https://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python) – Kushan Gunasekera Jan 26 '21 at 01:25
  • You'll want to use `os.stat` to get the inode number, see [this post](https://stackoverflow.com/questions/48656460/how-to-find-the-inode-of-all-files-in-linux-with-python). – costaparas Jan 26 '21 at 01:37
  • 1
    Does this answer your question? [How to find the inode of all files in Linux with Python?](https://stackoverflow.com/questions/48656460/how-to-find-the-inode-of-all-files-in-linux-with-python) – costaparas Jan 26 '21 at 01:37
  • @kushan that's not a suitable duplicate in this case, the question is about getting the inode number, not the absolute path – costaparas Jan 26 '21 at 01:38

0 Answers0