Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking to see if a file can be written to
Message
From
06/11/2002 13:54:59
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00719448
Message ID:
00719463
Views:
20
Michael,

Instead of closing the file, leave it open, and return the file handle. Returning negative number means you can't open file. However, I don't think you saving any lines of code by putting this in a function (maybe you are saving a line).

>Does anyone have a better way to do this, than the function below?
>
>
>*********************
>FUNCTION CanWrite
>*********************
>PARAM tcFile
>LOCAL llCanWrite,lnHandle
>IF NOT FILE(tcFile)
> *File doesn't exist, so it can be created.
> llCanWrite = .t.
>ELSE
> *If the file does exist, try to open it as
> *read/write.
> lnHandle = FOPEN(tcFile,2)
> llCanWrite = (lnHandle > 0)
> *Make sure the file gets closed. This will
> *leave the file vulnerable to get opened by
> *another person in the meantime.
> FCLOSE(lnHandle)
>ENDIF
>RETURN llCanWrite
>
Steve Gibson
Previous
Reply
Map
View

Click here to load this message in the networking platform