views:

549

answers:

2

Is there a way to tell when a file was moved to a certain directory?

I'm being asked why a script of mine did not find a file in a certain directory. The file was created last January but I suspect it was placed in the directory after the script was run. Is there a way for me to confirm my suspicion?

Viewing the file properties gives me the created, modified, and accessed times, and the first two do not change when moving files from one directory to another.


EDIT: I have cygwin installed, if that helps at all. Is there a unix way of determining when a directory entry was created?

+2  A: 

If the file in question can be shown to have been the last file added to that directory, you can look at the last modified date of the directory itself, since directories are modified when files are inserted into them. Otherwise, I don't hold much hope.

Jesse Pepper
The directory was modified yesterday. This isn't proof, but it definitely helps. Thanks!
MCS
A: 

If you're on Windows XP or 2000 or higher, you should be able to use dir /tc to get the creation time of the file (which will be when it was copied to the directory). Under Cygwin, you can use ls -lc.

Alex
The creation time is the time the file was actually created, not the time it was copied to the directory.
MCS
Is that really true? - If the file was moved from some other directory won't the create time move too and be unchanged? - Certainly, the modified time remains unchanged because of the move.
Tall Jeff
Indeed. The modified time (which is the default time used for file listings in both the CMD and Cygwin shells) won't change because the file was copied or moved. But the create time will. Try it yourself and see!
Alex