Carl Rynegardh
Carl Rynegardh

Reputation: 558

Reading the time a file was added to a folder

I am writing a piece of software that is to monitor the time a file was added into a specific directory. I would need to do this in both c# and java. However, I am not so much interested in when the files was created as this could be days before they are actually moved into the directory of interest. I have been loking around, but unable to find anything. The closest I've found so far in java is:

File file = new File(yourPathHere);
long lastModified = file.lastModified();

But that does not give me the time the file was moved into the folder. Thanks for help :)

Upvotes: 1

Views: 160

Answers (1)

Julien R
Julien R

Reputation: 404

if you are using windows, have a look at this rules :

https://support.microsoft.com/en-us/kb/299648

It seems that when you move a file, it does not change its modification or creation date. It's changed only when doing a copy.

As an alternative, you can regularly scan your folder, like every 1 minutes and when you discover a new file, you put it in a log and write it's discovery date.

As IInspectable is saying, FileSystemWatcher and FindFirstChangeNotification are probably the way to go to avoid coding a scanner

Upvotes: 2

Related Questions