mteg
mteg

Reputation: 55

How to get a file's arrival time to a directory using Perl?

Assume a file is copied or moved to a directory by some other program. I want to get the time that this file was copied/moved to this folder. That is, I want the time that the file first appears in this directory.

Note that this file might exist before it was moved/copied or it might not.

This is not any of the time information that can be obtained by File::stat. Thanks.

Upvotes: 1

Views: 165

Answers (4)

ysth
ysth

Reputation: 98398

If nothing else has happened in that directory, this will be the modification time of the directory.

Upvotes: 0

Ustit
Ustit

Reputation: 1

While it may not be the best way to do it, but for the copying case, if you make a file handle $fh, You can keep checking for file existence using -e $fh As soon as you find that file exists, record that moments time.

You may find more interesting -X $fileHandle stuff here.

Upvotes: 0

hwnd
hwnd

Reputation: 70732

You may find File::ChangeNotify helpful which tracks file and directory changes. I would suggest looking at incron, which can track various events and changes of files in filesystems.

Upvotes: 1

Jim Garrison
Jim Garrison

Reputation: 86774

My guess is you want the time the file was closed after being first written. This may or may not be available, and will be OS-specific. Most OSes track file creation, last modification, and last read (or some subset of those). If none of those work for you you're out of luck unless you control the creation and writing of the file in your application code, in which case you can use whatever you like.

Upvotes: 0

Related Questions