I extracted "d:\test_dir\test.pdf". Then used ShellExecute to open it. The user reads the pdf and later I want to erase it. But, it will not erase if the user has not previously closed it.
How can I tell if it is closed? Even better, is there a way I can close it?
Carl Lindner
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
Probably the easiest way is just trying to open it and trapping the error. So assuming you know the file exists then
lnHandle = fopen(lcMyFileName)
if lnHandle = -1 * -- The file couldn't be opened so is open somewhere else. else fclose(lnHandle) endif
To close it you would have to find the file handle from the other process, i.e. whatever they're using to read PDF files, and use the Windows API to close that handle. Bearing in mind that they could be using any web browser, Acrobat Reader or any number of PDF readers to view the PDF. Maybe extract it in their temp folder and don't worry about erasing it.
Alan,
Thanks for the response. I found an API that lists all files open. If the pdf is found, I force the user to close it.
Carl
-----Original Message----- From: ProFox [mailto:profox-bounces@leafe.com] On Behalf Of Alan Bourke Sent: Tuesday, March 29, 2022 11:45 AM To: profoxtech@leafe.com Subject: Re: Determine if a File is Open
Probably the easiest way is just trying to open it and trapping the error. So assuming you know the file exists then
lnHandle = fopen(lcMyFileName)
if lnHandle = -1 * -- The file couldn't be opened so is open somewhere else. else fclose(lnHandle) endif
To close it you would have to find the file handle from the other process, i.e. whatever they're using to read PDF files, and use the Windows API to close that handle. Bearing in mind that they could be using any web browser, Acrobat Reader or any number of PDF readers to view the PDF. Maybe extract it in their temp folder and don't worry about erasing it.