Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatic File Attribute changes? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all,

New here. I was wondering, did anyone know of a way to change file attributes on the fly from within a VFP app, without resorting to manual change (via Properties windows) or DOS commands? I'm surprised I haven't been able to find anything about this in the VFP documentation. (Well, maybe not *too* surprised).

Joe
Programmer
metalwar@snip.net
 
MetWar

Check out low level file function FOPEN(). It enables file attribute changes.

FOPEN(cFileName [, nAttribute])

Chris
 
Unfortunately, VFP does not have a native function for changing file attributes, unlike VB's SetAttr() function.

You can use the FileSystemObject of WSH:

oFSO=CreateObject('Scripting.FileSystemObject')
oFile = oFSO.GetFile('C:\windows\mytest.txt')
oFile.Attributes=1 && read only

or you can use the SetFileAttributes API function:

DECLARE INTEGER SetFileAttributes IN WIN32API STRING @, INTEGER

lcFile='C:\windows\mytest.txt'
SetFileAttributes(@lcFile,32) && Archive

FYI,
Normal 0 Normal file. No attributes are set.
ReadOnly 1 Read-only file. Attribute is read/write.
Hidden 2 Hidden file. Attribute is read/write.
System 4 System file. Attribute is read/write.
Directory 16 Folder or directory. Attribute is read-only.
Archive 32 File has changed since last backup. Attribute is read/write.
Alias 1024 Link or shortcut. Attribute is read-only.
Compressed 2048 Compressed file. Attribute is read-only.


Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,

When All We Want Is Unity. - Creed
 
I believe you can do this with FILER.DLL by setting the files collection's ATTR property. I know you can read them, and am 51% sure you can set them as well.

Only caveat: you can't distribute FILER.DLL with your EXE.

Robert Bradley

 
Does anyone know if it is ever possible to change the compresed file attribute at runtime
 
It is possible.. see faq184-3327 (though I don't think that addresses compressed directly, it is doable in the same way. You have to be on NTFS to have the "compressed" feature)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top