Repository navigation
Fileattr
Home › Operating System Functions › FileAttr
Returns an open file number's mode, system handle or encoding.
Declare Function FileAttr ( ByVal filenum As Long, ByVal returntype As Long = 1 ) As Integerfilenumreturntype
Information about the file number is returned based on the supplied returntype
| Value | Description | constant |
|---|---|---|
| 1 | File Mode | fbFileAttrMode |
| 2 | File Handle | fbFileAttrHandle |
| 3 | Encoding | fbFileAttrEncoding |
For File Mode, returntype = 1 (fbFileAttrMode) the return value is the sum of one or more of the following values:
| Value | File Mode | Constant |
|---|---|---|
| 1 | Input | fbFileModeInput |
| 2 | Output | fbFileModeOutput |
| 4 | Random | fbFileModeRandom |
| 8 | Append | fbFileModeAppend |
| 32 | Binary | fbFileModeBinary |
For File Handle, returntype = 2 (fbFileAttrHandle), the return value is the file handle as supplied by the C Runtime for file-type devices.
On Windows only: For File Handle, returntype = 2 (fbFileAttrHandle), the value returned for COM devices is the handle returned by CreateFile() when the device was first opened. The value returned for LPT devices is the handle returned by OpenPrinter() when the device was first opened. This handle value can be passed to other Windows API functions.
On Linux only: For File Handle, returntype = 2 (fbFileAttrHandle), the value returned for COM devices is the file descriptor returned by open() when the device was first opened.
For Encoding, returntype = 3 (fbFileAttrEncoding), the return value is one of the following values:
| Value | Encoding | Constant |
|---|---|---|
| 0 | Ascii | fbFileEncodASCII |
| 1 | UTF-8 | fbFileEncodUTF8 |
| 2 | UTF-16 | fbFileEncodUTF16 |
| 3 | UTF-32 | fbFileEncodUTF32 |
A value associated with the return type, otherwise 0 on error.
#include "file.bi"
result = FileAttr( filenum, [ returntype ] )or
#include "vbcompat.bi"
result = FileAttr( filenum, [ returntype ] )- None for
returntype= 1 - QBasic and 16-bit Visual Basic returned DOS file handle for
returntype= 2 -
returntype= 3 is new to FreeBASIC
#include "vbcompat.bi"
#include "crt.bi"
Dim f As FILE Ptr, i As Integer
'' Open a file and write some text to it
Open "test.txt" For Output As #1
f = Cast( FILE Ptr, FileAttr( 1, fbFileAttrHandle ))
For i = 1 To 10
fprintf( f, !"Line %i\n", i )
Next i
Close #1
'' re-open the file and read the text back
Open "test.txt" For Input As #1
f = Cast( FILE Ptr, FileAttr( 1, fbFileAttrHandle ))
While feof(f) = 0
i = fgetc(f)
Print Chr(i);
Wend
Close #1Category: Operating System Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing