I Get It Windows, Something Is Locking the File, But What Exactly?

My development environment  consists of several processes running together simulating various server and client applications.  Add a couple of open command prompts to the mix  and  the message:

The process cannot access the file because it is being used by another process.

appears every once in a while.

Windows wouldn’t tell which process is holding your file hostage.  That’s for it to know and you to find out.

In this post I introduce two tools that will help you interrogate the OS for  the  information:

Process Explorer

a free utility from Microsoft.   No installation required,  download it extract it from the zip archive and run.

Click Find  or enter Ctrl-F

image

In the find dialog, you can enter the name of the locked file.  After clicking search,  you can have the name and PID of the offending process.

image

LockHunter

This  freeware windows explorer extension that will  not only find the locking process, it will also let you kill that locking process or force unlocking the file.

You can download the file from lockhunter.com.  Once Installed you can right-click on a file from windows explorer and select What is locking this file? Or What is locking this folder?

image

Conclusion

I like guessing games as much as  the next person,  I just don’t want them in the middle a  busy work day.

File hunting: the express way (windows)

Searching for files is a recurring part in our work as developers.  It might be messing header file,  a file containing a function  name, a configuration file with a specific string etc.

Everything Search

a recurring scenario for me is cloning a repository from Git and getting this message while trying to compile it: “Cannot open include file: ‘someheader.h’: No such file or directory” 

I start to wonder – do I have this file at all?  the obvious solution is running a search on the file system. It’s not  a terribly long process but still it gets me out of the zone.

Enter  Everything Search – one of the pieces of software I install as soon as possible in a new  Windows development machine.  This little free utility reads the NTFS master file table directly as its starts up. Using the NTFS ready-made index, allows it to be ready for action in an incredibly short time  even when there are hundreds of  thousands of files.  Once the index is read it is updated in real time by getting file system change  notification from  the OS.

a search such as the one  described above, takes as  much time as it takes to enter the file name into the search box. The search results just snap into place covering your entire drive(s).  You can fix the build without breaking  your stride.

this utility is also invaluable when searching for none source files like configuration files and other resource files

image

Files can be matched by partial name ,  by regex  and other useful criteria, found in the search menu.  The  list of files can be sorted by clicking on the column header.

Docfetcher

While search everything is fast, it will not be able to provide you any information about the content your files.
suppose you are working on a team implementing server/client  protocol.

You, on the server side, want to remove a  string value declared in a protocol used  by both client and server. You are pretty sure nobody is using this value in the client sources, so you can safely remove it.  However,  being a responsible developer you do a  text search over  the entire client code – a no brainer albeit discarding task.  Now,   If you could only Google for the string like you do everything else….

as a matter of fact, you can!

Docfetcher is an open source desktop file indexing  utility.  It will  turn a folder and its subfolders  into  a searchable index,  as files  added/removed/modified in  the tracked folders  the index gets updated automatically.  Your text search is completed  in a fraction of the  time it will take you to do a full-text search on your files.

image

creating the index is as easy as adding your source root directory to the search scope, by right-clicking on it:

image

Once you select the directory, you can  add more files types to the plain text file list:

image

Pressing on the (…) button next to the field lets you add additional files extensions  available in the folder tree:

image

You can repeat the process, selecting additional directories – for example any other location where configuration files are stored.

DocFetcher is open source,  so yo can assure yourself by examining the utility source code , that  sensitive files  (like configuration files with database user names and passwords)  are not shared behind your back,    Like the ill-fated Google Desktop from a while ago

In addition to the rapid plain text search, which I find the most useful , DocFetcher has a search query syntax enabling you to easily query your files content. For example  “int number”~5   will find any file where number is up to 5 words apart from int ;    so this search will find both of these lines :

int number;
int index, number, value;
conclusions

While you can easily do both types of  searches with a  plain vanilla  grepdir or find  commands,  I  often find it more productive to use these tools instead, and use my time for actual development.