• Post Reply Bookmark Topic Watch Topic
  • New Topic

Running a batch file automatically whenever a file is placed inside a folder in Windows OS  RSS feed

 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I have a requirement where I need to run a batch file whenever a file is placed inside a folder in Windows. Is there a way to achieve this in java (configuring a windows listener or kind of) or even Windows itself ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Java 7? If so, you can use a watch service.
 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne. I will try that out. In the meanwhile , Is there a way to achieve this through Windows itself as i need to run my Utility in my end customer's machines and i cannot expect everyone to install Java.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows does have something called a scheduled task. You could set it up to run every 5 minutes, or 1 minute (I think). It wouldn't quite be 'real-time', but it may be close enough.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Are you using Java 7? If so, you can use a watch service.

Also, Java Service Wrapper can be used to run Java as a windows Service.
 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks surlac and Jeanne. Watch Service and Java Service Wrapper , both are a way to go!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!