Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I check if a file is open by any process?  RSS feed

 
Bala Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
How do I check if a certain file on the client desktop is open by any process?
Here is the scenario: I generate a vb script from an applet to print a pdf file. I do not know how long the file is being printed. So, I want to check of the file is open any process on the machine, so I can delete it when no process is using the file.
Thanks in advance.
Bala.
 
Andy Nimmo
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bala,
The File class has two methods called canRead( ) and canWrite( ).
I beleive that if you use either of these when they point to your File in question then they will tell you if there is any process maintaining a lock on it.

You might have tried this already, let me know if it solves your problem or not!
Andy.
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
canWrite answers the requirement.When another process is reading the file the canWrite() returns false.
Cheers,
Gaya3
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!