Fórum Ler e Modificar atributos de arquivos (Somente Leitura, etc) #196532

21/11/2003

0

Olá... tou iniciando em Delphi, e estou com uma dúvida quanto ao código... espero que eu não atrapalhe o andamento daqui (pq minhas dúvidas são bem simples)

Eu gostaria de saber como ler e modificar os atributos de um arquivo... (se ele é somente leitura, oculto, ou de sistema)

Até que consegui fazer ele ler os atributos...mas foi de um modo não mto prático.. hehe

bom, se alguém tiver algumas dicas e puder me ajudar como modificar esses atributos, eu agradeço...

Valeu, Nev.


Neville

Neville

Responder

Posts

22/11/2003

Lordglacius

Bem vindo amigo newbie :D !!

Procure no Help do Delphi sobre a função FileSetAttr. Ela vai solucionar seu problema...

Pra poupar seu trabalho, peguei um exemplozinho desta função... Lá vai: :wink:

The following code reads a file´s attributes into a set variable, sets the check boxes in a file-attribute dialog box to represent the current attributes, then executes the dialog box. If the user changes and accepts any dialog box settings, the code sets the file attributes to match the changed settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
procedure TFMForm.Properties1Click(Sender: TObject);
var
  Attributes, NewAttributes: Word;
begin
  with FileAttrForm do
  begin
    FileDirName.Caption := FileList.Items[FileList.ItemIndex];
    { set box caption }
    PathName.Caption := FileList.Directory;
    { show directory name }
    ChangeDate.Caption :=
      DateTimeToStr(FileDateToDateTime(FileAge(FileList.FileName)));
    Attributes := FileGetAttr(FileDirName.Caption);
    { read file attributes }
    ReadOnly.Checked := (Attributes and SysUtils.faReadOnly) = faReadOnly;
    Archive.Checked := (Attributes and faArchive) = faArchive;
    System.Checked := (Attributes and faSysFile) = faSysFile;
    Hidden.Checked := (Attributes and faHidden) = faHidden;
    if ShowModal <> id_Cancel then{ execute dialog box }
    begin
      NewAttributes := Attributes;
      { start with original attributes }
      if ReadOnly.Checked then
        NewAttributes := NewAttributes or SysUtils.faReadOnly
      else
        NewAttributes := NewAttributes and not SysUtils.faReadOnly;
      if Archive.Checked then
        NewAttributes := NewAttributes or faArchive
      else
        NewAttributes := NewAttributes and not faArchive;
      if System.Checked then
        NewAttributes := NewAttributes or faSysFile
      else
        NewAttributes := NewAttributes and not faSysFile;
      if Hidden.Checked then
        NewAttributes := NewAttributes or faHidden
      else
        NewAttributes := NewAttributes and not faHidden;
      if NewAttributes <> Attributes then { if anything changed... }
        FileSetAttr(FileDirName.Caption, NewAttributes);
         { ...write the new values }
    end;
  end;
end;


[]´s 8)


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar