1

I have a folder with alot of different data types (xls, doc, ....). If there is a new file with some specific file extension (.avi) && the first letter of the file name starts with "EN_", the file should be moved to another folder. This should be run continuously, means when some file got moved it starts immediately with scanning for the next file with the specific properties (.avi & EN_). With my current knowledge I just would use a endless while loop. Is there maybe any other solution? How would you solve it?

Thanks in advance.

Panther
  • 15
  • 1
  • 6

3 Answers3

1

You could try to use JNotify library, it should be more efficient than a while loop: http://jnotify.sourceforge.net/

I never used it, but I think this library makes use of OS specific features. For example, in Linux you have inotify, which allows you to listen for filesystem events.

P.S. As mentioned in another thread, you should you Java 7 new file API for this: How does Jnotify works

Community
  • 1
  • 1
Konstantin Milyutin
  • 11,946
  • 11
  • 59
  • 85
0

You could write a infinite loop that makes use of a try catch. Try to find the file, if it is not there it will execute the catch.

Tenzin
  • 2,415
  • 2
  • 23
  • 36
  • bad idea. he should have a look here: http://java.dzone.com/news/how-watch-file-system-changes `...` but of course the Panther should have used Google `;)` – Benjamin M Mar 29 '15 at 17:26
0

With Java 8 you can create a WatchService.

It will allow you to watch for changes to a directory of a certain type.

David S.
  • 6,567
  • 1
  • 25
  • 45