Link to home
Start Free TrialLog in
Avatar of ryan_sabarre
ryan_sabarre

asked on

Setting Attribute to a file

H0W can i Change the Attribute of a file
example.

 from hidden to visible
 from Readonly to deletable or editable
 etc.
Avatar of ryan_sabarre
ryan_sabarre

ASKER

please help me
Something likd this

var
     wAttrb: Word;
     sTheFile: string;

begin
     sTheFile := 'C:\aHiddenFile.txt';
     wAttrb := sTheFile
                FileSetAttr(sTheFile , wAttrb and not faHidden);

end;




faReadOnly     $00000001     Read-only files
faHidden     $00000002     Hidden files
faSysFile     $00000004     System files
faVolumeID     $00000008     Volume ID files
faDirectory     $00000010     Directory files
faArchive     $00000020     Archive files
faAnyFile     $0000003F     Any file



The Crazy One
ASKER CERTIFIED SOLUTION
Avatar of chengjian
chengjian

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops this

    wAttrb := sTheFile

Sould be

    wAttrb := FileGetAttr(sTheFile);
you could use the API
SetFileAttributes(PChar(FileName), FILE_ATTRIBUTE_NORMAL);

this will get rid of all arributes

some of the attributes you can set are
FILE_ATTRIBUTE_ARCHIVE
FILE_ATTRIBUTE_HIDDEN
FILE_ATTRIBUTE_OFFLINE
FILE_ATTRIBUTE_READONLY
FILE_ATTRIBUTE_SYSTEM
FILE_ATTRIBUTE_TEMPORARY


combine them with the "or"

SetFileAttributes(PChar(FileName), FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY);
Thanks so much