Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC GetAttr function provides file information. Works on
'open or closed files.
'Primary Code:
'Syntax: x& = GETATTR(filespec$)
'Example#1 - tests for a single property
result& = GetAttr(filespec$,1) '0-Normal 1-ReadOnly 2-Hidden 4-System
'8-VolumeLabel 16-Directory 32-Archived 128-Normal
'Example#2
Function IsProperty(filespec$, MyProperty%) as Long
Local x&
x& = GetAttr(filespec$)
Function = x& AND MyProperty%
End Function
'Compilable Example: (Jose Includes)
'In this example, the Function above is modified to return a string
'consisting of all set properties.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$, filehandle&, filespec$
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
FileHandle& = FreeFile 'ensure FileHandle& is not in use
FileSpec$ = "myfile.txt"
Open FileSpec$ For Output As FileHandle& 'File is now Open
If IsProperty(FileSpec$, %Normal) Then temp$ = temp$ + "%Normal" + $crlf
If IsProperty(FileSpec$, %ReadOnly) Then temp$ = temp$ + "%ReadOnly" + $crlf
If IsProperty(FileSpec$, %Hidden) Then temp$ = temp$ + "%Hidden" + $crlf
If IsProperty(FileSpec$, %System) Then temp$ = temp$ + "%System" + $crlf
If IsProperty(FileSpec$, %vLabel) Then temp$ = temp$ + "%vLabel" + $crlf
If IsProperty(FileSpec$, %SubDir) Then temp$ = temp$ + "%SubDir" + $crlf
If IsProperty(FileSpec$, %Archive) Then temp$ = temp$ + "%Archive" + $crlf
MsgBox "myfile.txt" + $crlf + $crlf + temp$
Close FileHandle&
End If
End Function
Function IsProperty(filespec$, MyProperty%) as Long
Local x&
x& = GetAttr(filespec$)
Function = x& AND MyProperty%
End Function
'gbs_00149
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm