Skip to content

Instantly share code, notes, and snippets.

@CarlTBarnes
Last active January 3, 2022 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlTBarnes/e2b1f07fcc306192c32995c03249d28b to your computer and use it in GitHub Desktop.
Save CarlTBarnes/e2b1f07fcc306192c32995c03249d28b to your computer and use it in GitHub Desktop.
Path Exists or File Exists functions versus Clarion Exists()
!Clarion Exists() returns True whethere File or Directory. These functions will check explicitly for File or Path.
MAP
FileExists(STRING FileName,<*LONG OutAttributes>),BOOL !Return 1 if FileName exists and is File not Directory
PathExists(STRING PathName,<*LONG OutAttributes>),BOOL !Return 1 if PathName exists and is Directory not File
ExistsFileOrPath(STRING FileOrPathName,<*LONG OutAttributes>),BYTE !Return 1=File 2=Path 0=N/A
MODULE('Win32')
GetFileAttributes(*CSTRING FileName),LONG,PASCAL,RAW,DLL(1),NAME('GetFileAttributesA')
END
END
!---------------------------------------------------------------------------
FileExists PROCEDURE(STRING FN, <*LONG OutAttr>)!,BOOL !1=File
cName CSTRING(261),AUTO
Attr LONG,AUTO
!_INVALID_FILE_ATTRIBUTES EQUATE(-1) !If function fails it returns INVALID_FILE_ATTRIBUTES. Call GetLastError() for error information,
!_FILE_ATTRIBUTE_DIRECTORY EQUATE(10h) !The handle that identifies a directory
CODE
cName=CLIP(FN)
Attr = GetFileAttributes(cName)
IF ~OMITTED(OutAttr) THEN OutAttr=Attr.
RETURN CHOOSE(Attr <> -1 AND ~BAND(Attr,10h))
!---------------------------------------------------------------------------
PathExists PROCEDURE(STRING FN, <*LONG OutAttr>)!,BOOL !1=Path
cName CSTRING(261),AUTO
Attr LONG,AUTO
!_INVALID_FILE_ATTRIBUTES EQUATE(-1) !If function fails it returns INVALID_FILE_ATTRIBUTES. Call GetLastError() for error information,
!_FILE_ATTRIBUTE_DIRECTORY EQUATE(10h) !The handle that identifies a directory
CODE
cName=CLIP(FN)
Attr = GetFileAttributes(cName)
IF ~OMITTED(OutAttr) THEN OutAttr=Attr.
RETURN CHOOSE(Attr <> -1 AND BAND(Attr,10h))
!---------------------------------------------------------------------------
ExistsFileOrPath PROCEDURE(STRING FN, <*LONG OutAttr>)!,BYTE !1=File 2=Path
cName CSTRING(261),AUTO
Attr LONG,AUTO
ForP12 BYTE
!_INVALID_FILE_ATTRIBUTES EQUATE(-1) !If function fails it returns INVALID_FILE_ATTRIBUTES. Call GetLastError() for error information,
!_FILE_ATTRIBUTE_DIRECTORY EQUATE(10h) !The handle that identifies a directory
CODE
cName=CLIP(FN)
Attr = GetFileAttributes(cName)
IF ~OMITTED(OutAttr) THEN OutAttr=Attr.
IF Attr <> -1 THEN ForP12=CHOOSE(~BAND(Attr,10h),1,2).
RETURN ForP12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment