1

When I open a file in Python with f = open("filename.txt"), I can access the filename using the name property (file_object.name). However, if that file is moved to another path, the name property isn't updated.

I can detect that the file has moved by opening the file again, calling stat and comparing the inode, but I couldn't find a way to get the new name of the original file. Is this possible? If not in Python, is there a way in C? Posix? Linux?

felipou
  • 654
  • 6
  • 16
  • From the dupe: *however, if the file was moved or deleted since then, it may no longer be accurate* – Martijn Pieters Oct 19 '16 at 14:57
  • 1
    Also on the dupe: the answer by zneak supports the file being moved, but it only worked on Mac OS X when I tested it, and it's not available on Python (F_GETPATH is not defined on Python's fcntl). – felipou Oct 19 '16 at 16:54

0 Answers0