4

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?

MCS
  • 22,113
  • 20
  • 62
  • 76

3 Answers3

3

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
  • 3,225
  • 28
  • 48
  • The directory was modified yesterday. This isn't proof, but it definitely helps. Thanks! – MCS Jan 09 '09 at 02:22
1

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
  • 2,366
  • 1
  • 15
  • 10
  • The creation time is the time the file was actually created, not the time it was copied to the directory. – MCS Jan 09 '09 at 03:06
  • 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 Jan 09 '09 at 03:06
  • 1
    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 Jan 09 '09 at 05:21
  • Windows is weird, on Windows 8.1, if I delete a file & recreate a new file with same name in same directory , creation date-time is shown to be old one & same is the case with file copy. – Sabir Khan Apr 04 '18 at 06:34
0

Using wmic and or creating a layer for yourself really helps when using cyging. For example a function like this will return everything in the actual windows properties dialog for a file...

finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}

This way regardless of how the file was touched you have multiple ways of knowing.

CMD Line FU Info link

jonretting
  • 412
  • 2
  • 6