Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1476
  • Last Modified:

File attribute

How to get and change a file attribute from Powerbuilder?
0
magotici
Asked:
magotici
  • 3
1 Solution
 
buasuwanCommented:
You need an External Function to get file attributes.

first, declare an External Function.

Function long GetFileAttributes (string lpFileName) Library "kernel32" Alias for "GetFileAttributesA"

second, some constants.

Constant long FILE_ATTRIBUTE_ARCHIVE = 32
Constant long FILE_ATTRIBUTE_COMPRESSED = 2048
Constant long FILE_ATTRIBUTE_DIRECTORY = 16
Constant long FILE_ATTRIBUTE_HIDDEN = 2
Constant long FILE_ATTRIBUTE_NORMAL = 128
Constant long FILE_ATTRIBUTE_READONLY = 1
Constant long FILE_ATTRIBUTE_SYSTEM = 4
Constant long FILE_ATTRIBUTE_TEMPORARY = 256

and then codes,

long     ll_attributes
ll_attributes = GetFileAttributes("C:\AUTOEXEC.BAT")

ll_atttibutes contains attributes of above constants.

and,
this sample codes for checking that file has ARCHIVE attribute or not.

long     ll_bit

ll_bit = mod(ll_attributes, FILE_ATTRIBUTE_ARCHIVE * 2) / FILE_ATTRIBUTE_ARCHIVE

ll_bit = 1, an archive file
ll_bit = 0, not archive file.

and you can change parameter to test other attribute that you want.


0
 
magoticiAuthor Commented:
Thank you.
And how to change an attribute?
Manuel
0
 
buasuwanCommented:
and setting file attributes,
you need more function.

Function boolean SetFileAttributes(string lpFileName, long dwFileAttributes) Library "kernel32" Alias for "SetFileAttributesA"

and script is,

boolean lb_result
lb_result = SetFileAttributes("C:\AUTOEXEC.BAT", FILE_ATTRIBUTE_READONLY)



0
 
buasuwanCommented:
or

boolean lb_result
lb_result = SetFileAttributes("C:\AUTOEXEC.BAT", FILE_ATTRIBUTE_READONLY + FILE_ATTRIBUTE_ARCHIVE )
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now