FileLocker - a small tool to lock files

Did you also sometimes want to test exception cases and the right tools are missing?

I recently wanted to test a locked file exception in Java but from implementing the test it seems there is no easy way in Windows to lock a file for testing (at least I'm not aware of, hints are welcome...) - so I was writing a small command line tool to help me implementing my test cases.

The FileLocker is a Windows NT/2000/XP/2003/Vista/7 32Bit command line tool to lock a file. The lock is a read/write/delete lock. The lock will be released once you kill the program or after a specified time / keypress.

Usage:

FileLocker [/T LockTime] [/I] [/K] [/Q] file [file...]
/T LockTime Time in milliseconds to lock the file
/I Infinite locking until process is killed (default)
/K Lock file until key is pressed
/Q Be quiet.

 

AttachmentSize
FileLocker.zip15.45 KB
FileLockerSource.zip9.47 KB

Nice Work

Thanks for the tool, I was needing to test locked file handling as well.  Works great...so does my error handling now :)

 

David

Hi, I would like to use this

Hi,

I would like to use this tool in a batchscript for that:

1. set a exclusive lock on file test.log

2. copy test.log with FastCopy to another path

3. unlock the file test.log 

Is it possible to do this with your tool or is it possible to change the tool.

Thanks for your help

Gunther

Hi Gunther,   I assume you

Hi Gunther,

 

I assume you need to make a script / batch file around the tool to get the desired results:

  1. Start FileLocker as a seperate process
  2. sleep for 1 second
  3. Start FastCopy
  4. kill the FlieLocker process to remove the lock, use "killall" for example

Jens

Exactly what I was looking for!

During development, the need arose to test a case when a local file is locked by another program.

Thanks a lot for this small tool, it simplified my work a lot!