check whether file is open

Hello Lee Curcon,

tanks for your fast suggestion,

but my problem is an other. i dont want to know whether the file is lockt, i want to know whether the file is opened. i copy a "BLOB" from an database to the local hdd, progress have to know whether the file is opened on local pc, when it is not opened, progress can copy it back to database and can delete the local file.

greetings
andi
 
ok,

Well there are a couple of WinApi Open / Lock methods that you can call passing a 'Share Exclusive' parameter, which will deny access to other processes.

If the file is already open, the call fails - which gives you your IsFileOpen test.

You may also be able to do this with the CreateFile call in the David Rozen link I posted, but I don't think the parameter applies in that case.

For more info:

http://msdn.microsoft.com/library/d...en-us/fileio/fs/file_management_functions.asp

eg. LZOpenFile

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/lzopenfile.asp

Unfortunately, I don't have enough knowledge of the API to know if this is the correct method to do what you want.
 
Apparently, setting dwshare mode to 0 with CreateFile means it can't be shared - which may do what you want - and you already have code to experiment with.

Here's a Knowledge base entry with a stupid title that has an example, although you may need to experiment with the READ/WRITE parameter.

P26125
Title: "How to check if a file is busy using 4GL?"

http://tinyurl.com/eupa3

Hope that works for you, although I suspect the earlier examples I suggested may work better (if the parameter types are compatible with Progress).
 
i don't think you can tell whether a file is still open in some app. worst case, an app can just read the file into memory and be done with it.

but most modern app lock files while editing e.g. excel, word etc.


another thing you can do is use shellexec to launch the app and open/edit document and write a process (you could use pstimer) that checks whether the app process has been closed.

but even that won't work all the time. some apps use mdi in which case you'll get multiple windows/files for a single process (or something like that ?).


maybe a cross between them will cover most cases ?

you could issue a notice in cases that don't, telling the user the file would have to be loaded manually.


personally, i wouldn't do neither of them.

start by letting the users save the file to disk and load them back after they've finished making changes.

later on when you've got everything together or a better idea you can gradually improve on it. hth
 
i experimented with the idea ... i've got some free time next week

interested in contracting the job ?
 
If you don't get anywhere with the previous suggestions, try querying the output from this cool little util (can be run from the command line, so you should be able to call it from 4GL).

It's extremely fast, and reports all opened files to a format you choose (XML/Text/etc.).

http://www.nirsoft.net/utils/opened_files_view.html

If you find it useful, send Joey's commission straight to me.
 
[Humble Pie eating]

Just tested them, and like Joey said, for some files (eg. small text/image files), no handle is reported, even though they are open.

Ah well, at least I found a new util.
 
good morning (in germany it is 09:30 AM),

thanks for all your suggestions, im really responsive about the helpfulness in this forum.

Regrettably, im unable to engage with it, im trainee as IT specialist and my project (document-storage in an production planning and control system) must be complete in 2 weeks. I wont make a lock on the database when a file is in use, everybody can open and save every document at every time, changed documents will save in a new version of it. i think that is the easiest way.

thanks again, i will visit the forum from time to time.

greetings
Andi
 
i checked my idea on the following apps, worked so far !

notepad, wordpad, word, excel, powerpoint, acrobat, mspaint, photoshop,
winzip, winrar and progress client.

you can also write general purpose print and open with procedures.
 
Back
Top