Reading File Attributes
The Code
The following code will display the attributes of the file C:\AREADING.TAB.
declare function GetFileAttributes filename = 'C:\areading.tab' EQU FILE_NOT_FOUND$ to -1 EQU FILE_ATTRIBUTE_READONLY$ to 1 EQU FILE_ATTRIBUTE_HIDDEN$ to 2 EQU FILE_ATTRIBUTE_SYSTEM$ to 4 EQU FILE_ATTRIBUTE_DIRECTORY$ to 16 EQU FILE_ATTRIBUTE_ARCHIVE$ to 32 EQU FILE_ATTRIBUTE_NORMAL$ to 128 EQU FILE_ATTRIBUTE_TEMPORARY$ to 256 attributes = GetFileAttributes (filename) if attributes = FILE_NOT_FOUND$ then call msg( filename : ' was not found!') end else if bitand( attributes , FILE_ATTRIBUTE_READONLY$) then call msg( filename : ' is a readonly file.') end if bitand( attributes , FILE_ATTRIBUTE_HIDDEN$) then call msg( filename : ' is hidden file.') end if bitand( attributes , FILE_ATTRIBUTE_SYSTEM$) then call msg( filename : ' is system file.') end if bitand( attributes , FILE_ATTRIBUTE_DIRECTORY$) then call msg( filename : ' is directory.') end if bitand( attributes , FILE_ATTRIBUTE_ARCHIVE$) then call msg( filename : ' is an archive file.') end if bitand( attributes , FILE_ATTRIBUTE_NORMAL$) then call msg( filename : ' is a normal file.') end if bitand( attributes , FILE_ATTRIBUTE_TEMPORARY$) then call msg( filename : ' is a temporary file.') end call msg(@window , 'attributes = ': attributes) end
The attributes are returned in one byte, in the attributes variable. Each bit is equated to its decimal equivalent. If more than one bit is set, these values are added.
The Windows API Declaration
The code above will not run until the declaration for GetFileAttributes() has been added. To add the declaration, do the following:
- Log out of the application.
- Log into the SYSPROG application.
- Add a row, (call it DLL_APICALLS_KERNEL32), with the first line as KERNEL32 and containing the declarations as shown below.
KERNEL32 LONG STDCALL GetFileAttributesA(LPCHAR) as GetFileAttributes //....add any other declarations in KERNEL32 here.....
The function is aliased to its the ANSI version GetFileAttributesA().
- Save the row.
- Run Declare_FCNS at the System Editor Exec Line to create the declaration header, as shown below:
RUN DECLARE_FCNS 'DLL_APICALLS_KERNEL32'
- Exit the editor.
- Log out of SYSPROG.
- Log into your application.
- Run the window.