Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to check file and directory attributes Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-Oct-02
Category
Files Operation
Language
Delphi 2.x
Views
59
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to check file and directory attributes

Answer:

The sample below works with the folder c:\temp .
1   
2   procedure TForm1.Button1Click(Sender: TObject);
3   var
4     Ergebnis: integer;
5     Hidden: boolean;
6     ReadOnly: boolean;
7     Directory: boolean;
8   begin
9     {Get the current file attributes and store them in a local bool variable.
10    lbl_hidden, lbl_ReadOnly and lbl_Directory are TLabels}
11    Ergebnis := fileGetAttr('C:\Temp');
12    if Ergebnis and faHidden <> 0 then
13    begin
14      hidden := True;
15      lbl_hidden.Caption := 'Hidden File';
16    end
17    else
18    begin
19      Hidden := False;
20      lbl_hidden.Caption := 'Not a hidden file';
21    end;
22    if Ergebnis and faDirectory <> 0 then
23    begin
24      Directory := True;
25      lbl_Directory.Caption := 'We have a directory';
26    end
27    else
28    begin
29      Directory := False;
30      lbl_Directory.Caption := 'There is no directory';
31    end;
32    if Ergebnis and faReadOnly <> 0 then
33    begin
34      ReadOnly := True;
35      lbl_ReadOnly.Caption := 'File is write-protected';
36    end
37    else
38    begin
39      ReadOnly := False;
40      lbl_ReadOnly.Caption := 'File is not write-protected';
41    end;
42    refresh;
43    sleep(4000);
44    {Set attributes}
45    FileSetAttr('C:\Temp', faHidden or faReadOnly or faDirectory);
46    {Check set attributes and reset Ergebnis variable to original status}
47    Ergebnis := FileGetAttr('C:\Temp');
48    if Ergebnis and faHidden <> 0 then
49    begin
50      lbl_hidden.Caption := 'Attribute Hidden is set'; {TLabel}
51      if not hidden then
52        Ergebnis := Ergebnis xor fahidden;
53    end
54    else
55      lbl_hidden.Caption := 'Attribute Hidden is not set';
56    if Ergebnis and faReadOnly <> 0 then
57    begin
58      lbl_ReadOnly.Caption := 'Attribute Read Only is set';
59      if not ReadOnly then
60        Ergebnis := Ergebnis xor faReadOnly;
61    end
62    else
63      lbl_ReadOnly.Caption := 'Attribute ReadOnly not set';
64    if Ergebnis and faDirectory <> 0 then
65    begin
66      lbl_Directory.Caption := 'Directory set';
67      if not Directory then
68        Ergebnis := Ergebnis xor faDirectory;
69    end
70    else
71      lbl_Directory.Caption := 'Directory not set';
72    refresh;
73    sleep(4000);
74    {Reset attributes}
75    FileSetAttr('C:\Temp', Ergebnis);
76    {Check if attributes were reset correctly}
77    Ergebnis := fileGetAttr('C:\Temp');
78    if Ergebnis and faHidden <> 0 then
79      lbl_hidden.Caption := 'Hidden file'
80    else
81      lbl_hidden.Caption := 'Not a hidden file';
82    if Ergebnis and faDirectory <> 0 then
83      lbl_Directory.Caption := 'We have a directory'
84    else
85      lbl_Directory.Caption := 'There is no directory';
86    if Ergebnis and faReadOnly <> 0 then
87      lbl_ReadOnly.Caption := 'File is write-protected'
88    else
89      lbl_ReadOnly.Caption := 'File is not write-protected';
90    refresh;
91  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC