var FileName: string; Attr: Integer; //属性值是一个整数begin FileName := 'c:\temp\Test.txt'; //设置为隐藏和只读文件: Attr := FILE_ATTRIBUTE_HIDDEN; if FileSetAttr(FileName,Attr)=0 then //返回0表示成功 ShowMessage('设置成功!');end;
还是自己回答好了 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure set(s:string); private { Private declarations } pusetic { Pusetic declarations } end;var Form1: TForm1; rec_stack:array [1..30] of TSearchRec; rec_pointer:integer; set_Flag:Boolean; implementation{$R *.dfm}procedure TForm1.set(s:string); VAR searchRec:TSearchRec; begin if FindFirst(s+'\*.*', faAnyFile, SearchRec)=0 then repeat if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then begin if (SearchRec.Attr and faDirectory>0) then begin rec_stack[rec_pointer]:=SearchRec; rec_pointer:=rec_pointer-1;
set(s+'\'+SearchRec.Name);
rec_pointer:=rec_pointer+1; SearchRec:=rec_stack[rec_pointer]; end else begin try FileSetAttr(s+'\'+SearchRec.Name,faHidden); except //Application.MessageBox(PChar('setete File:'+s+'\'+SearchRec.Name+' Error!'),'Info',MB_OK); set_Flag:=False; end; end; end; until (FindNext(SearchRec)<>0); FindClose(SearchRec); if rec_pointer<30 then begin try FileSetAttr(s,faHidden); //RemoveDir(s); except //Application.MessageBox(PChar('setete Directory:'+s+' Error!'),'Info',MB_OK); set_Flag:=False; end; end; end;procedure TForm1.Button1Click(Sender: TObject); begin set_Flag:=True; rec_pointer:=30; set('C:\Documents and Settings\All Users\「开始」菜单\程序'); set('C:\Documents and Settings\Administrator\「开始」菜单\程序'); if set_Flag then Application.MessageBox(PChar('设置成功!'),'信息',MB_OK); end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure set(s:string);
private
{ Private declarations }
pusetic
{ Pusetic declarations }
end;var
Form1: TForm1;
rec_stack:array [1..30] of TSearchRec;
rec_pointer:integer;
set_Flag:Boolean;
implementation{$R *.dfm}procedure TForm1.set(s:string);
VAR searchRec:TSearchRec;
begin
if FindFirst(s+'\*.*', faAnyFile, SearchRec)=0 then
repeat
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
begin
if (SearchRec.Attr and faDirectory>0) then
begin
rec_stack[rec_pointer]:=SearchRec;
rec_pointer:=rec_pointer-1;
set(s+'\'+SearchRec.Name);
rec_pointer:=rec_pointer+1;
SearchRec:=rec_stack[rec_pointer];
end
else
begin
try
FileSetAttr(s+'\'+SearchRec.Name,faHidden);
except
//Application.MessageBox(PChar('setete File:'+s+'\'+SearchRec.Name+' Error!'),'Info',MB_OK);
set_Flag:=False;
end;
end;
end;
until (FindNext(SearchRec)<>0);
FindClose(SearchRec);
if rec_pointer<30 then
begin
try
FileSetAttr(s,faHidden);
//RemoveDir(s);
except
//Application.MessageBox(PChar('setete Directory:'+s+' Error!'),'Info',MB_OK);
set_Flag:=False;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
set_Flag:=True;
rec_pointer:=30;
set('C:\Documents and Settings\All Users\「开始」菜单\程序');
set('C:\Documents and Settings\Administrator\「开始」菜单\程序');
if set_Flag then
Application.MessageBox(PChar('设置成功!'),'信息',MB_OK);
end;end.