Page 1 of 1

Checking For File being open

Posted: Wed Dec 17, 2014 12:15 pm
by omni
Roger,

This is not for a dbf, just to clarify.

We import images, some users importing hundreds at a time to attach to different data files. Recently at one of our sites the import is crashing because somebody on the other end has one of the image files open. We fail in copying the file to the image save folder, and also will eventually fail when attempting to erase it when completed.
Is there a method to check to see if the file can be copied and just skip it until the next import? Not exactly an express or alaska quesiton, but thought somebody else may have run across this type of issue. Maybe some sort of if(copy) or something that already exists.

Thanks,

Fred
Omni

Re: Checking For File being open

Posted: Wed Dec 17, 2014 12:53 pm
by Tom

Re: Checking For File being open

Posted: Wed Dec 17, 2014 1:33 pm
by bwolfsohn
if erasing, you can also use fexists to check if the file is still there..

on copying, you can compare date/times/sizes after the copy

Re: Checking For File being open

Posted: Wed Dec 17, 2014 1:38 pm
by omni
Rogers bit of code at the end is what was needed. Worked perfect.

Thanks

Re: Checking For File being open

Posted: Mon Dec 22, 2014 8:56 am
by Eugene Lutsenko
When Roger is such a decision, Kotra works well. It may be suitable in this case?

Code: Select all

**********************************************************
******** Проверка, открыт файл или нет (от Роджера Доннея)
**********************************************************
FUNCTION IsFileOpened( cFileName )

*#include "fileio.ch"
LOCAL lStatus := .F.       // Файл cFileName закрыт
LOCAL nHandle := FOpen( cFileName, FO_READWRITE+FO_DENYWRITE )

IF nHandle <= 0
  lStatus := .T.           // Файл cFileName открыт или его нет
ELSE
  FClose(nHandle)
ENDIF

RETURN lStatus
And Tom advised to determine whether or not a file is opened on the fact of the existence of a temporary file, which is generated when opening and udalat at closing.