Windows – how to get the full path of an open file

network-sharescriptingwindows

I have script that runs on a Windows server to perform operations on certain files. The script often fails because various users (even myself) have open file shares on the server that they've forgotten to close, so the folders are locked.

I've added code to check for open files with net file, and close them if they match certain patterns. The limitation there is that net file summarizes the path of the open files, e.g.

ID         Path                                    User name            # Locks
-------------------------------------------------------------------------------
2          C:\Program Files\...\cocoon-2.1.11\     huttarl               0

when the full path of the open file is

C:\Program Files\Apache Software Foundation\cocoon-2.1.11

So when my script checks that the file path matches a certain pattern, such as "Apache", it sometimes misses files that have ... in the middle of their net file listing.

So my question is, how can I get the full path of an open file, in a script?

Currently, I'm using cygwin/bash. So if I have to switch to WSH, there will be some porting to do. But if that's the only option, I'll go for it.

If it matters, the system information panel says my Windows edition is Windows Server Standard, (c) 2007, SP2.

Best Answer

I have found the following useful:

openfiles /query /v | findstr "string what You want"