GETATTR function

Purpose:

GETATTR is used for obtaining file attributes.

Syntax:

Attribs = GETATTR(FileName AS STRING)

Return Value:

  • Data type: INTEGER
    Attribs Any combination of the following list of file attribute values
    • A read-only file
      FILE_ATTRIBUTE_READONLY = 1
    • A hidden file, not normally visible to the user.
      FILE_ATTRIBUTE_HIDDEN = 2
    • A system file, used exclusively by the operating system.
      FILE_ATTRIBUTE_SYSTEM = 4
    • A directory instead of a file.
      FILE_ATTRIBUTE_DIRECTORY = 16
    • An archive file(which most files are).
      FILE_ATTRIBUTE_ARCHIVE = 32
    • An attribute-less file (cannot be combined with other attributes).
      FILE_ATTRIBUTE_NORMAL = 128
    • A file being used for temporary storage
      FILE_ATTRIBUTE_TEMPORARY = 256
    • A file residing in a compressed drive or directory.
      FILE_ATTRIBUTE_COMPRESSED = 2048

Parameters:

  • Data type: STRING
    FileName The name of the file from which attributes are to be obtained.

Example:

DIM attribs%
DIM int1%

$COMMENT

 FILE_ATTRIBUTE_READONLY = 1
 A read-only file.

 FILE_ATTRIBUTE_HIDDEN = 2
 A hidden file.

 FILE_ATTRIBUTE_SYSTEM = 4
 A system file, used by the operating system.

 FILE_ATTRIBUTE_DIRECTORY = 16
 A directory instead of a file.

 FILE_ATTRIBUTE_ARCHIVE = 32
 An archive flag marking a file for backup.

 FILE_ATTRIBUTE_NORMAL = 128
 A file with no attributes.

 FILE_ATTRIBUTE_COMPRESSED = 2048
 A file in a compressed drive or directory.

$COMMENT

attribs% = GETATTR("myfile.bas") ' read file attributes

int1% = attribs% AND FILE_ATTRIBUTE_READONLY
IF int1% <> 0 THEN
  PRINT "Read-only"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_HIDDEN
IF int1% <> 0 THEN
  PRINT "Hidden"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_SYSTEM
IF int1% <> 0 THEN
  PRINT "System"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_DIRECTORY
IF int1% <> 0 THEN
  PRINT "directory"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_ARCHIVE
IF int1% <> 0 THEN
  PRINT "Archive flag set"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_NORMAL
IF int1% <> 0 THEN
  PRINT "Normal, no other attributes set"
END IF

int1% = attribs% AND FILE_ATTRIBUTE_COMPRESSED
IF int1% <> 0 THEN
  PRINT "File in Compressed Drive or directory"
END IF

BCX Console Sample Programs using the GETATTR function.

SETATTR statement

Purpose:

SETATTR is used for setting file attributes.

Syntax:

SETATTR(FileName AS STRING, Attribs AS INTEGER)

Parameters:

  • Data type: STRING
    FileName Name of file in which attributes are to be set.
  • Data type: INTEGER
    Attribs Attributes value to be set which is a combination of
    • A read-only file
      FILE_ATTRIBUTE_READONLY = 1
    • A hidden file, not normally visible to the user.
      FILE_ATTRIBUTE_HIDDEN = 2
    • A system file, used exclusively by the operating system.
      FILE_ATTRIBUTE_SYSTEM = 4
    • An archive file(which most files are).
      FILE_ATTRIBUTE_ARCHIVE = 32
    • An attribute-less file (cannot be combined with other attributes).
      FILE_ATTRIBUTE_NORMAL = 128
    • A file being used for temporary storage
      FILE_ATTRIBUTE_TEMPORARY = 256

ISFILE function

Purpose:

ISFILE is used to determine if an identifier is the name of a file.

Syntax:

IsItFile = ISFILE(Identifier AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    Identifier The name of a file/directory.
    do not use wildcards. Pass only a unique name Identifier.
    do not terminate the name of the Identifier with a trailing backslash (\).
    For example, if "C:\path\to\your\WhatIsIt" exists,
    IsItFile = ISFILE("C:\path\to\your\WhatIsIt\") ' This will return FALSE. 
                                                   ' Remove the trailing "\"
    IsItFile = ISFILE("C:\path\to\your\WhatIsIt")  ' This will return TRUE.
    
    The ISFILE function uses the FindFirstFile Win32-API function, which does not allow backslash termination.

Remarks:

👉 ISFILE is self-contained and should not interfere with, nor be interfered by, unrelated invocations of FINDFIRST$ or FINDNEXT$.

Example:

PRINT BOOL$(ISFILE(WINDIR$))

Result:

FALSE

ISFOLDER function

Purpose:

ISFOLDER is used to determine if an identifier is the name of a directory.

Syntax:

IsItFolder = ISFOLDER(Identifier AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    Identifier The name of a file/directory.
    do not use wildcards. Pass only a unique name Identifier.
    do not terminate the name of the Identifier with a trailing backslash (\).
    For example, if "C:\path\to\your\WhatIsIt" exists,
    IsItFolder = ISFOLDER("C:\path\to\your\WhatIsIt\") ' This will return FALSE.
                                                       ' Remove the trailing "\"
    IsItFolder = ISFOLDER("C:\path\to\your\WhatIsIt")  ' This will return TRUE.
    
    The ISFOLDER function uses the FindFirstFile Win32-API function, which does not allow backslash termination.

Remarks:

👉 ISFOLDER is self-contained and should not interfere with, nor be interfered by, unrelated invocations of FINDFIRST$ or FINDNEXT$.

Example 1:

PRINT BOOL$(ISFOLDER(WINDIR$))

Result:

TRUE

Example 2:

DIM AS STRING TheFolder
TheFolder = TEMPDIR$ & "TheFolder"
MKDIR(TheFolder)

DIM MyFileHandle@
DIM AS STRING TheFile
TheFile = TheFolder & "\TheFile"
OPEN TheFile FOR OUTPUT AS FP1
MyFileHandle@ = FP1
FPRINT MyFileHandle@, "This is " & TheFile
CLOSE FP1

PRINT

PRINT "It is ", BOOL$(ISFOLDER(TheFolder)), " that ", TheFolder, " is a folder."
PRINT "It is ", BOOL$(ISFILE(TheFile)), " that ", TheFile, " is a file."

PRINT

KILL TheFile
IF NOT EXIST(TheFile) THEN
  PRINT "The file ", TheFile, " has been removed."
ELSE
  PRINT "The file ", TheFile, " could not be removed."
END IF

PRINT

IF NOT RMDIR(TheFolder) THEN
  PRINT "RMDIR removed the folder " & TheFolder
ELSE
  PRINT "RMDIR could not remove the folder " & TheFolder
END IF

PAUSE

Result:

It is True that C:\Users\YouSir\AppData\Local\Temp\TheFolder is a folder.
It is True that C:\Users\YouSir\AppData\Local\Temp\TheFolder\TheFile is a file.

The file C:\Users\YouSir\AppData\Local\Temp\TheFolder\TheFile has been removed.

RMDIR removed the folder C:\Users\YouSir\AppData\Local\Temp\TheFolder

Press any key to continue . . .

ISHIDDEN function

Purpose:

ISHIDDEN is used to determine if an identifier is the name of a hidden file/directory.

Syntax:

IsItHidden = ISHIDDEN(Identifier AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    Identifier The name of a file/directory.
    do not use wildcards. Pass only a unique name Identifier.
    do not terminate the name of the Identifier with a trailing backslash (\).
    For example, if "C:\path\to\your\WhatIsIt" exists,
    IsItHidden = ISHIDDEN("C:\path\to\your\WhatIsIt\") ' This will return FALSE.
                                                       ' Remove the trailing "\"
    IsItHidden = ISHIDDEN("C:\path\to\your\WhatIsIt")  ' This will return TRUE.
    
    The ISHIDDEN function uses the FindFirstFile Win32-API function, which does not allow backslash termination.

Remarks:

👉 ISHIDDEN is self-contained and should not interfere with, nor be interfered by, unrelated invocations of FINDFIRST$ or FINDNEXT$.

Example:

PRINT BOOL$(ISHIDDEN(ENVIRON$("USERPROFILE") & "\AppData"))

Result:

TRUE

ISREADONLY function

Purpose:

ISREADONLY is used to determine if an identifier is the name of a read only file/directory.

Syntax:

IsItReadOnly = ISREADONLY(Identifier AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    Identifier The name of a file/directory.
    do not use wildcards. Pass only a unique name Identifier.
    do not terminate the name of the Identifier with a trailing backslash (\).
    For example, if "C:\path\to\your\WhatIsIt" exists,
    IsItReadOnly = ISREADONLY("C:\path\to\your\WhatIsIt\") ' This will return FALSE.
                                                           ' Remove the trailing "\"
    IsItReadOnly = ISREADONLY("C:\path\to\your\WhatIsIt")  ' This will return TRUE.
    
    The ISREADONLY function uses the FindFirstFile Win32-API function, which does not allow backslash termination.

Remarks:

👉 ISREADONLY is self-contained and should not interfere with, nor be interfered by, unrelated invocations of FINDFIRST$ or FINDNEXT$.

Example:

PRINT BOOL$(ISREADONLY(WINDIR$))

Result:

TRUE

ISSYSTEM function

Purpose:

ISSYSTEM is used to determine if an identifier is the name of a system file/directory.

Syntax:

IsItSystem = ISSYSTEM(Identifier AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    Identifier The name of a file/directory.
    do not use wildcards. Pass only a unique name Identifier.
    do not terminate the name of the Identifier with a trailing backslash (\).
    For example, if "C:\path\to\your\WhatIsIt" exists,
    IsItSystem = ISSYSTEM("C:\path\to\your\WhatIsIt\") ' This will return FALSE.
                                                       ' Remove the trailing "\"
    IsItSystem = ISSYSTEM("C:\path\to\your\WhatIsIt")  ' This will return TRUE.
    
    The ISSYSTEM function uses the FindFirstFile Win32-API function, which does not allow backslash termination.

Remarks:

👉 ISSYSTEM is self-contained and should not interfere with, nor be interfered by, unrelated invocations of FINDFIRST$ or FINDNEXT$.

Example:

PRINT BOOL$(ISSYSTEM(WINDIR$))

Result:

TRUE