Can we read the file property
I mean if they are read only or hide and others
if we can read that can we change the property
if anyone has a idea about this
thanks in advance
Printable View
Can we read the file property
I mean if they are read only or hide and others
if we can read that can we change the property
if anyone has a idea about this
thanks in advance
Quote:
MSDN
GetAttr Function
Returns an Integer representing the attributes of a file, directory, or folder.
Syntax
GetAttr(pathname)
The required pathname argument is a string expression that specifies a file name. The pathname may include the directory or folder, and the drive.
Return Values
The value returned by GetAttr is the sum of the following attribute values:
Constant Value Description
vbNormal 0 Normal.
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file.
vbDirectory 16 Directory or folder.
vbArchive 32 File has changed since last backup.
Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.
Remarks
To determine which attributes are set, use the And operator to perform a bitwise comparison of the value returned by the GetAttr function and the value of the individual file attribute you want. If the result is not zero, that attribute is set for the named file. For example, the return value of the following And expression is zero if the Archive attribute is not set:
Result = GetAttr(FName) And vbArchive
A nonzero value is returned if the Archive attribute is set.
Quote:
MSDN
SetAttr Statement
Sets attribute information for a file.
Syntax
SetAttr pathname, attributes
The SetAttr statement syntax has these named arguments:
Part Description
pathname Required. String expression that specifies a file name — may include directory or folder, and drive.
attributes Required. Constant or numeric expression, whose sum specifies file attributes.
Settings
The attributes argument settings are:
Constant Value Description
vbNormal 0 Normal (default).
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file.
vbArchive 32 File has changed since last backup.
Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.
Remarks
A run-time error occurs if you try to set the attributes of an open file.
Thanks Peet
But if the file is read only how can i set the read only off
any suggestion ?
VB Code:
Private Sub Command1_Click() SetAttr "C:\TEST.TXT", vbNormal End Sub
will turn all attrib. off
If you want to set more than one attribute at the time, you just add them :)
example
VB Code:
Private Sub Command1_Click() SetAttr "C:\TEST.TXT", vbArchive + vbHidden End Sub
if test1.txt was f.ex. just read only, it will after the sample is run have the Archive and Hidden attrib sat.
am I making sense ? :)
Thanks Peet
that was wat I needid
no problemo :)