[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change file attributes?

Posted on 2004-09-22
6
Medium Priority
?
3,253 Views
Last Modified: 2011-09-20
I have a text file that I add entries to, through my code.
Unfortunately, the file is stored in a folder where it 'might' get deleted.  I'd like to make it RO, but that would prohibit my code from opening it for append.  How can I remove the RO and then readd it in VB6?
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12122080
There is SetFileAttributes API

Const READONLY = &H1
Const HIDDEN = &H2
Const SYSTEM = &H4
Const ARCHIVE = &H20
Const NORMAL = &H80
Private Declare Function SetFileAttributes Lib "kernel32.dll" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long

Private Sub Form_Load()
Dim attr As Long
Dim rval As Long
attr = READONLY + SYSTEM + HIDDEN
rval = SetFileAttributes(YoorFile, attr)
End Sub
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 12122101
You can try to do this:

SetAttr "TESTFILE", vbNormal

SetAttr "TESTFILE", vbReadOnly     ' Set read-only
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 12122108
SetAttr Statement

Description - Sets attribute information for a file.
Syntax - SetAttr pathname,attributes

The SetAttr statement syntax has these named-argument parts:
Part - Description
pathname -  String expression that specifies a file name — may include directory or folder, and drive.
attributes - Constant or numeric expression, the sum of which specifies file attributes.

Constants and values for attributes are:
vbNormal - 0 - Normal (default).
vbReadOnly - 1 Read-only.
vbHidden - 2 - Hidden.
vbSystem - 4 - System — not available on the Macintosh.
vbArchive - 32 - File has changed since last backup — not available on the Macintosh.

Note

These constants are specified by Visual Basic. As a result, 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.

See Also
FileAttr Function, GetAttr Function.
Example
This example uses the SetAttr statement to set attributes for a file.
SetAttr "TESTFILE", vbHidden    ' Set hidden attribute.
SetAttr "TESTFILE", vbHidden + vbReadOnly    ' Set hidden and Read-only
    ' attributes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Author Comment

by:sirbounty
ID: 12123504
Dhaest - love the simple solution!
However, I'm curious is it a complete change?
For instance, if I have RASH - and I use vbNormal - is that now 'no' attribs?
If it's none and I wanted to specify HS - is it just A + B (or 6)?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12169349
"Ping"
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 12169381
About your question, I'm not sure. I guess the easiest way to find out is to test it. I just needed like the cases above.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question