• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to identify file exists period in a directory  RSS feed

 
hariharan jayaprakash
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to identify how long a particular file exists in a directory

I have two directories In/Out

Files which is In directory has been moved to Out directory.. But i want to identify if the files is not moved from In directory for more than 30 mins.

i.e. Based on the duration on file which is not been moved(for example 30 mins).


Is there any API to achieve this?
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about Java for the moment.

The question is, can you do it in the operating system your Java code is going to run on?
If not, then there isn't going to be an inbuilt way of doing this.

I can't offhand think of a way that either Windows or Linux tracks the movement of files.
That's not to say it doesn't exist, I've just never seen it.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hang on.
I think I read your question backwards.

I thought you wanted to know about files in the Out directory.

If (as I now read it) you just want to know how long a file was in in the In directory can't you just use the created date, or (if it was moved to the In directory after creation) the modified date?
 
hariharan jayaprakash
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Files will be placed by automation process in that IN directory... (we cant use created date that may be any date). I want to identify after it comes to IN directory.. Is that file not been moved to OUT directory in another 30 mins...


I have to create a process to identify how many files in that above scenario matches and need to get all the file names. !!

Hope i am clear.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the date modified tell you when a file was moved? Or is it when it was last updated? If the latter, is this thing about moving files possible at all?I found a file with last modification date 26th April last year, moved it out of the folder and moved it back and this is the new modification date:-
Modified Date: 2016-04-23T10:31:40
Exactly the same as before. That was GMT/UTC; since we have summer time in April, you can add an hour to that time. That suggests my Linux box doesn't record movement into or out of a folder, and my detector finds nothing to detect. Had I edited the file, I would have got 2017-07-04TXXXXXXdisplayed. Try the same on a Windows® box. Feel free to use my code. It will only work on Java8.

Does the File class have more date methods than last modified? I didn't find any.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I was wondering.
This is going to be down to the OS, at least without writing your own code.
If (and at least with Linux it looks like this is the case) the OS does not treat a move as a change, you have nothing to hook into to monitor this.

The only thing you can do is monitor the IN directory and track the files "by hand", so to speak.
Have one task that monitors when a file appears, note the filename and time in a db (say).
have a another task that scans the directory for files checking against the db, flagging any "old" ones, and removing any in the db that no longer exist.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!