vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="VB6Parse Library Reference - getattr - File">
    <title>getattr - File - VB6Parse Library Reference</title>
    <link rel="stylesheet" href="../../../assets/css/style.css">
    <link rel="stylesheet" href="../../../assets/css/docs-style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
    <script src="../../../assets/js/theme-switcher.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
    <header class="docs-header">
        <div class="container">
            <h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/file/index.html">File</a> / getattr</h1>
            <p class="tagline">VB6 Library Reference</p>
        </div>
    </header>

    <nav class="docs-nav">
        <div class="container">
            <a href="../../../index.html">Home</a>
            <a href="../../../library/index.html">Library Reference</a>
            <a href="../../../documentation.html">Documentation</a>
            <a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
            <a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
            <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
                <span class="theme-icon">🌙</span>
            </button>
        </div>
    </nav>

    <main class="container">
        
        <article class="library-item">
            <p>GetAttr Function
Returns an Integer representing the attributes of a file, directory, or folder.</p>
<h1 id="syntax">Syntax</h1>
<pre><code class="language-vbnet">GetAttr(pathname)</code></pre>
<h1 id="parameters">Parameters</h1>
<ul>
<li><code>pathname</code> - Required. String expression that specifies a file name. May include directory or folder, and drive.</li>
</ul>
<h1 id="return-value">Return Value</h1>
<p>Returns an Integer representing the sum of the following attribute values:</p>
<table>
<thead>
<tr>
<th>Constant</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>vbNormal</td>
<td>0</td>
<td>Normal (no attributes set)</td>
</tr>
<tr>
<td>vbReadOnly</td>
<td>1</td>
<td>Read-only</td>
</tr>
<tr>
<td>vbHidden</td>
<td>2</td>
<td>Hidden</td>
</tr>
<tr>
<td>vbSystem</td>
<td>4</td>
<td>System file</td>
</tr>
<tr>
<td>vbVolume</td>
<td>8</td>
<td>Volume label</td>
</tr>
<tr>
<td>vbDirectory</td>
<td>16</td>
<td>Directory or folder</td>
</tr>
<tr>
<td>vbArchive</td>
<td>32</td>
<td>File has changed since last backup</td>
</tr>
<tr>
<td>vbAlias</td>
<td>64</td>
<td>Specified file name is an alias (Macintosh only)</td>
</tr>
</tbody>
</table>
<h1 id="remarks">Remarks</h1>
<ul>
<li>Use the And operator to test for a specific attribute.</li>
<li>The return value can be a combination of multiple attributes.</li>
<li>To check if a file has a specific attribute, use bitwise AND comparison.</li>
<li><code>GetAttr</code> generates an error if the file doesn't exist.</li>
<li>Use <code>Dir</code> to check if a file exists before calling <code>GetAttr</code>.</li>
<li>On systems other than Macintosh, <code>vbAlias</code> is never set.</li>
<li>The <code>vbVolume</code> constant is used for volume labels only.</li>
</ul>
<h1 id="typical-uses">Typical Uses</h1>
<ul>
<li>Checking if a file is read-only before attempting to modify it</li>
<li>Detecting hidden or system files</li>
<li>Verifying if a path points to a directory</li>
<li>Determining file attributes for backup operations</li>
<li>Filtering files based on attributes</li>
<li>Security and permission checks</li>
</ul>
<h1 id="basic-usage-examples">Basic Usage Examples</h1>
<pre><code class="language-vbnet">&#x27; Check if file is read-only
Dim attr As Integer
attr = GetAttr(&quot;C:\data.txt&quot;)
If attr And vbReadOnly Then
    MsgBox &quot;File is read-only&quot;
End If
&#x27; Check if path is a directory
Dim pathAttr As Integer
pathAttr = GetAttr(&quot;C:\MyFolder&quot;)
If pathAttr And vbDirectory Then
    MsgBox &quot;This is a directory&quot;
End If
&#x27; Check for hidden file
Dim fileAttr As Integer
fileAttr = GetAttr(&quot;C:\hidden.sys&quot;)
If fileAttr And vbHidden Then
    MsgBox &quot;File is hidden&quot;
End If
&#x27; Check for system file
If GetAttr(&quot;C:\Windows\System32\ntoskrnl.exe&quot;) And vbSystem Then
    MsgBox &quot;This is a system file&quot;
End If</code></pre>
<h1 id="common-patterns">Common Patterns</h1>
<h2 id="1-check-read-only-before-writing">1. Check Read-Only Before Writing</h2>
<pre><code class="language-vbnet">Sub WriteToFile(filename As String, content As String)
    Dim attr As Integer
    On Error GoTo ErrorHandler
    attr = GetAttr(filename)
    If attr And vbReadOnly Then
        MsgBox &quot;Cannot write to read-only file: &quot; &amp; filename
        Exit Sub
    End If
    &#x27; Proceed with writing
    Dim fileNum As Integer
    fileNum = FreeFile
    Open filename For Output As #fileNum
    Print #fileNum, content
    Close #fileNum
    Exit Sub
ErrorHandler:
    MsgBox &quot;Error accessing file: &quot; &amp; Err.Description
End Sub</code></pre>
<h2 id="2-detect-directory-vs-file">2. Detect Directory vs File</h2>
<pre><code class="language-vbnet">Function IsDirectory(path As String) As Boolean
    On Error GoTo ErrorHandler
    Dim attr As Integer
    attr = GetAttr(path)
    IsDirectory = (attr And vbDirectory) &lt;&gt; 0
    Exit Function
ErrorHandler:
    IsDirectory = False
End Function
&#x27; Usage
If IsDirectory(&quot;C:\Windows&quot;) Then
    Debug.Print &quot;Path is a directory&quot;
Else
    Debug.Print &quot;Path is a file&quot;
End If</code></pre>
<h2 id="3-find-hidden-files">3. Find Hidden Files</h2>
<pre><code class="language-vbnet">Sub ListHiddenFiles(folderPath As String)
    Dim filename As String
    Dim fullPath As String
    Dim attr As Integer
    filename = Dir(folderPath &amp; &quot;\*.*&quot;, vbHidden)
    Do While filename &lt;&gt; &quot;&quot;
        fullPath = folderPath &amp; &quot;\&quot; &amp; filename
        On Error Resume Next
        attr = GetAttr(fullPath)
        On Error GoTo 0
        If (attr And vbHidden) And Not (attr And vbDirectory) Then
            Debug.Print &quot;Hidden file: &quot; &amp; filename
        End If
        filename = Dir
    Loop
End Sub</code></pre>
<h2 id="4-check-multiple-attributes">4. Check Multiple Attributes</h2>
<pre><code class="language-vbnet">Function GetFileAttributeDescription(filename As String) As String
    Dim attr As Integer
    Dim description As String
    On Error GoTo ErrorHandler
    attr = GetAttr(filename)
    description = &quot;&quot;
    If attr = vbNormal Then
        description = &quot;Normal&quot;
    Else
        If attr And vbReadOnly Then description = description &amp; &quot;Read-Only &quot;
        If attr And vbHidden Then description = description &amp; &quot;Hidden &quot;
        If attr And vbSystem Then description = description &amp; &quot;System &quot;
        If attr And vbDirectory Then description = description &amp; &quot;Directory &quot;
        If attr And vbArchive Then description = description &amp; &quot;Archive &quot;
    End If
    GetFileAttributeDescription = Trim(description)
    Exit Function
ErrorHandler:
    GetFileAttributeDescription = &quot;Error: &quot; &amp; Err.Description
End Function</code></pre>
<h2 id="5-safe-file-delete">5. Safe File Delete</h2>
<pre><code class="language-vbnet">Function SafeDeleteFile(filename As String) As Boolean
    Dim attr As Integer
    On Error GoTo ErrorHandler
    &#x27; Check if file exists and get attributes
    attr = GetAttr(filename)
    &#x27; Don&#x27;t delete system or read-only files
    If attr And vbSystem Then
        MsgBox &quot;Cannot delete system file: &quot; &amp; filename
        SafeDeleteFile = False
        Exit Function
    End If
    &#x27; Remove read-only attribute if set
    If attr And vbReadOnly Then
        SetAttr filename, attr And Not vbReadOnly
    End If
    &#x27; Delete the file
    Kill filename
    SafeDeleteFile = True
    Exit Function
ErrorHandler:
    MsgBox &quot;Error deleting file: &quot; &amp; Err.Description
    SafeDeleteFile = False
End Function</code></pre>
<h2 id="6-list-files-by-attribute">6. List Files by Attribute</h2>
<pre><code class="language-vbnet">Sub ListFilesByAttribute(folderPath As String, attributeFlag As Integer)
    Dim filename As String
    Dim fullPath As String
    Dim attr As Integer
    filename = Dir(folderPath &amp; &quot;\*.*&quot;, vbNormal + vbHidden + vbSystem)
    Do While filename &lt;&gt; &quot;&quot;
        fullPath = folderPath &amp; &quot;\&quot; &amp; filename
        On Error Resume Next
        attr = GetAttr(fullPath)
        On Error GoTo 0
        If (attr And attributeFlag) And Not (attr And vbDirectory) Then
            Debug.Print filename &amp; &quot; (Attribute: &quot; &amp; attr &amp; &quot;)&quot;
        End If
        filename = Dir
    Loop
End Sub
&#x27; Usage
ListFilesByAttribute &quot;C:\Temp&quot;, vbArchive  &#x27; List files needing backup</code></pre>
<h2 id="7-backup-file-scanner">7. Backup File Scanner</h2>
<pre><code class="language-vbnet">Function NeedsBackup(filename As String) As Boolean
    Dim attr As Integer
    On Error GoTo ErrorHandler
    attr = GetAttr(filename)
    &#x27; Check if archive bit is set
    NeedsBackup = (attr And vbArchive) &lt;&gt; 0
    Exit Function
ErrorHandler:
    NeedsBackup = False
End Function
Sub FindFilesNeedingBackup(folderPath As String, lst As ListBox)
    Dim filename As String
    Dim fullPath As String
    lst.Clear
    filename = Dir(folderPath &amp; &quot;\*.*&quot;)
    Do While filename &lt;&gt; &quot;&quot;
        fullPath = folderPath &amp; &quot;\&quot; &amp; filename
        If NeedsBackup(fullPath) Then
            lst.AddItem filename
        End If
        filename = Dir
    Loop
End Sub</code></pre>
<h2 id="8-file-permission-check">8. File Permission Check</h2>
<pre><code class="language-vbnet">Function CanModifyFile(filename As String) As Boolean
    Dim attr As Integer
    On Error GoTo ErrorHandler
    attr = GetAttr(filename)
    &#x27; File can be modified if it&#x27;s not read-only and not a system file
    CanModifyFile = Not ((attr And vbReadOnly) Or (attr And vbSystem))
    Exit Function
ErrorHandler:
    CanModifyFile = False
End Function
Sub ModifyFileIfAllowed(filename As String)
    If CanModifyFile(filename) Then
        &#x27; Proceed with modification
        Debug.Print &quot;File can be modified&quot;
    Else
        Debug.Print &quot;File is protected&quot;
    End If
End Sub</code></pre>
<h2 id="9-directory-tree-walker">9. Directory Tree Walker</h2>
<pre><code class="language-vbnet">Sub WalkDirectory(path As String, Optional level As Integer = 0)
    Dim filename As String
    Dim fullPath As String
    Dim attr As Integer
    Dim indent As String
    indent = String(level * 2, &quot; &quot;)
    filename = Dir(path &amp; &quot;\*.*&quot;, vbDirectory)
    Do While filename &lt;&gt; &quot;&quot;
        If filename &lt;&gt; &quot;.&quot; And filename &lt;&gt; &quot;..&quot; Then
            fullPath = path &amp; &quot;\&quot; &amp; filename
            On Error Resume Next
            attr = GetAttr(fullPath)
            On Error GoTo 0
            If attr And vbDirectory Then
                Debug.Print indent &amp; &quot;[DIR] &quot; &amp; filename
                WalkDirectory fullPath, level + 1
            Else
                Debug.Print indent &amp; filename
            End If
        End If
        filename = Dir
    Loop
End Sub</code></pre>
<h2 id="10-file-attribute-report">10. File Attribute Report</h2>
<pre><code class="language-vbnet">Sub GenerateAttributeReport(folderPath As String)
    Dim filename As String
    Dim fullPath As String
    Dim attr As Integer
    Dim normalCount As Long
    Dim readOnlyCount As Long
    Dim hiddenCount As Long
    Dim systemCount As Long
    Dim archiveCount As Long
    filename = Dir(folderPath &amp; &quot;\*.*&quot;, vbNormal + vbHidden + vbSystem)
    Do While filename &lt;&gt; &quot;&quot;
        fullPath = folderPath &amp; &quot;\&quot; &amp; filename
        On Error Resume Next
        attr = GetAttr(fullPath)
        On Error GoTo 0
        If Not (attr And vbDirectory) Then
            If attr = vbNormal Then normalCount = normalCount + 1
            If attr And vbReadOnly Then readOnlyCount = readOnlyCount + 1
            If attr And vbHidden Then hiddenCount = hiddenCount + 1
            If attr And vbSystem Then systemCount = systemCount + 1
            If attr And vbArchive Then archiveCount = archiveCount + 1
        End If
        filename = Dir
    Loop
    Debug.Print &quot;File Attribute Report for: &quot; &amp; folderPath
    Debug.Print String(50, &quot;=&quot;)
    Debug.Print &quot;Normal: &quot; &amp; normalCount
    Debug.Print &quot;Read-Only: &quot; &amp; readOnlyCount
    Debug.Print &quot;Hidden: &quot; &amp; hiddenCount
    Debug.Print &quot;System: &quot; &amp; systemCount
    Debug.Print &quot;Archive: &quot; &amp; archiveCount
End Sub</code></pre>
<h1 id="advanced-usage">Advanced Usage</h1>
<h2 id="1-file-attribute-manager-class">1. File Attribute Manager Class</h2>
<pre><code class="language-vbnet">&#x27; Class: FileAttributeManager
Private m_Filename As String
Private m_Attributes As Integer
Public Sub LoadFile(filename As String)
    m_Filename = filename
    RefreshAttributes
End Sub
Private Sub RefreshAttributes()
    On Error Resume Next
    m_Attributes = GetAttr(m_Filename)
    On Error GoTo 0
End Sub
Public Property Get IsReadOnly() As Boolean
    IsReadOnly = (m_Attributes And vbReadOnly) &lt;&gt; 0
End Property
Public Property Let IsReadOnly(value As Boolean)
    If value Then
        SetAttr m_Filename, m_Attributes Or vbReadOnly
    Else
        SetAttr m_Filename, m_Attributes And Not vbReadOnly
    End If
    RefreshAttributes
End Property
Public Property Get IsHidden() As Boolean
    IsHidden = (m_Attributes And vbHidden) &lt;&gt; 0
End Property
Public Property Let IsHidden(value As Boolean)
    If value Then
        SetAttr m_Filename, m_Attributes Or vbHidden
    Else
        SetAttr m_Filename, m_Attributes And Not vbHidden
    End If
    RefreshAttributes
End Property
Public Property Get IsDirectory() As Boolean
    IsDirectory = (m_Attributes And vbDirectory) &lt;&gt; 0
End Property
Public Property Get AttributeValue() As Integer
    AttributeValue = m_Attributes
End Property</code></pre>
<h2 id="2-smart-file-filter">2. Smart File Filter</h2>
<pre><code class="language-vbnet">Type FileFilter
    IncludeReadOnly As Boolean
    IncludeHidden As Boolean
    IncludeSystem As Boolean
    IncludeArchive As Boolean
    ExcludeDirectories As Boolean
End Type
Function MatchesFilter(filename As String, filter As FileFilter) As Boolean
    Dim attr As Integer
    On Error GoTo ErrorHandler
    attr = GetAttr(filename)
    &#x27; Check exclusions first
    If filter.ExcludeDirectories And (attr And vbDirectory) Then
        MatchesFilter = False
        Exit Function
    End If
    &#x27; Check inclusions
    MatchesFilter = True
    If Not filter.IncludeReadOnly And (attr And vbReadOnly) Then
        MatchesFilter = False
    ElseIf Not filter.IncludeHidden And (attr And vbHidden) Then
        MatchesFilter = False
    ElseIf Not filter.IncludeSystem And (attr And vbSystem) Then
        MatchesFilter = False
    ElseIf Not filter.IncludeArchive And (attr And vbArchive) Then
        MatchesFilter = False
    End If
    Exit Function
ErrorHandler:
    MatchesFilter = False
End Function</code></pre>
<h2 id="3-attribute-change-monitor">3. Attribute Change Monitor</h2>
<pre><code class="language-vbnet">Type FileSnapshot
    Filename As String
    Attributes As Integer
    Timestamp As Date
End Type
Private m_Snapshots As Collection
Sub InitializeMonitor()
    Set m_Snapshots = New Collection
End Sub
Sub TakeSnapshot(filename As String)
    Dim snapshot As FileSnapshot
    snapshot.Filename = filename
    snapshot.Attributes = GetAttr(filename)
    snapshot.Timestamp = Now
    m_Snapshots.Add snapshot, filename
End Sub
Function DetectAttributeChanges(filename As String) As Boolean
    Dim currentAttr As Integer
    Dim snapshot As FileSnapshot
    Dim i As Long
    currentAttr = GetAttr(filename)
    &#x27; Find snapshot
    For i = 1 To m_Snapshots.Count
        snapshot = m_Snapshots(i)
        If snapshot.Filename = filename Then
            DetectAttributeChanges = (snapshot.Attributes &lt;&gt; currentAttr)
            Exit Function
        End If
    Next i
    DetectAttributeChanges = False
End Function</code></pre>
<h2 id="4-bulk-attribute-operations">4. Bulk Attribute Operations</h2>
<pre><code class="language-vbnet">Sub SetAttributeForMultipleFiles(filenames() As String, _
                                 attributeToSet As Integer, _
                                 enable As Boolean)
    Dim i As Long
    Dim currentAttr As Integer
    Dim newAttr As Integer
    For i = LBound(filenames) To UBound(filenames)
        On Error Resume Next
        currentAttr = GetAttr(filenames(i))
        If enable Then
            newAttr = currentAttr Or attributeToSet
        Else
            newAttr = currentAttr And Not attributeToSet
        End If
        SetAttr filenames(i), newAttr
        On Error GoTo 0
    Next i
End Sub
&#x27; Usage
Sub MakeFilesReadOnly()
    Dim files() As String
    files = Array(&quot;file1.txt&quot;, &quot;file2.txt&quot;, &quot;file3.txt&quot;)
    SetAttributeForMultipleFiles files, vbReadOnly, True
End Sub</code></pre>
<h2 id="5-file-security-analyzer">5. File Security Analyzer</h2>
<pre><code class="language-vbnet">Type SecurityIssue
    Filename As String
    IssueType As String
    Severity As String
End Type
Function AnalyzeFileSecurity(folderPath As String) As Collection
    Dim issues As New Collection
    Dim filename As String
    Dim fullPath As String
    Dim attr As Integer
    Dim issue As SecurityIssue
    filename = Dir(folderPath &amp; &quot;\*.*&quot;, vbNormal + vbHidden + vbSystem)
    Do While filename &lt;&gt; &quot;&quot;
        fullPath = folderPath &amp; &quot;\&quot; &amp; filename
        On Error Resume Next
        attr = GetAttr(fullPath)
        On Error GoTo 0
        If Not (attr And vbDirectory) Then
            &#x27; Check for security issues
            &#x27; Issue 1: System files that are not hidden
            If (attr And vbSystem) And Not (attr And vbHidden) Then
                issue.Filename = filename
                issue.IssueType = &quot;System file not hidden&quot;
                issue.Severity = &quot;Medium&quot;
                issues.Add issue
            End If
            &#x27; Issue 2: Important files not marked read-only
            If InStr(1, filename, &quot;config&quot;, vbTextCompare) &gt; 0 Then
                If Not (attr And vbReadOnly) Then
                    issue.Filename = filename
                    issue.IssueType = &quot;Config file not read-only&quot;
                    issue.Severity = &quot;Low&quot;
                    issues.Add issue
                End If
            End If
        End If
        filename = Dir
    Loop
    Set AnalyzeFileSecurity = issues
End Function</code></pre>
<h2 id="6-attribute-comparison-tool">6. Attribute Comparison Tool</h2>
<pre><code class="language-vbnet">Function CompareFileAttributes(file1 As String, file2 As String) As String
    Dim attr1 As Integer
    Dim attr2 As Integer
    Dim differences As String
    On Error GoTo ErrorHandler
    attr1 = GetAttr(file1)
    attr2 = GetAttr(file2)
    differences = &quot;&quot;
    If (attr1 And vbReadOnly) &lt;&gt; (attr2 And vbReadOnly) Then
        differences = differences &amp; &quot;Read-Only differs&quot; &amp; vbCrLf
    End If
    If (attr1 And vbHidden) &lt;&gt; (attr2 And vbHidden) Then
        differences = differences &amp; &quot;Hidden differs&quot; &amp; vbCrLf
    End If
    If (attr1 And vbSystem) &lt;&gt; (attr2 And vbSystem) Then
        differences = differences &amp; &quot;System differs&quot; &amp; vbCrLf
    End If
    If (attr1 And vbArchive) &lt;&gt; (attr2 And vbArchive) Then
        differences = differences &amp; &quot;Archive differs&quot; &amp; vbCrLf
    End If
    If differences = &quot;&quot; Then
        CompareFileAttributes = &quot;Attributes are identical&quot;
    Else
        CompareFileAttributes = &quot;Differences found:&quot; &amp; vbCrLf &amp; differences
    End If
    Exit Function
ErrorHandler:
    CompareFileAttributes = &quot;Error: &quot; &amp; Err.Description
End Function</code></pre>
<h1 id="error-handling">Error Handling</h1>
<pre><code class="language-vbnet">Function SafeGetAttr(pathname As String, _
                     Optional defaultValue As Integer = -1) As Integer
    On Error GoTo ErrorHandler
    SafeGetAttr = GetAttr(pathname)
    Exit Function
ErrorHandler:
    Select Case Err.Number
        Case 53  &#x27; File not found
            Debug.Print &quot;File not found: &quot; &amp; pathname
        Case 76  &#x27; Path not found
            Debug.Print &quot;Path not found: &quot; &amp; pathname
        Case 68  &#x27; Device unavailable
            Debug.Print &quot;Device unavailable: &quot; &amp; pathname
        Case Else
            Debug.Print &quot;Error &quot; &amp; Err.Number &amp; &quot;: &quot; &amp; Err.Description
    End Select
    SafeGetAttr = defaultValue
End Function</code></pre>
<p>Common errors:
- <strong>Error 53 (File not found)</strong>: The specified file doesn't exist.
- <strong>Error 76 (Path not found)</strong>: The specified path doesn't exist.
- <strong>Error 68 (Device unavailable)</strong>: Network drive or removable media not available.</p>
<h1 id="performance-considerations">Performance Considerations</h1>
<ul>
<li><code>GetAttr</code> is a fast file system call</li>
<li>Use <code>Dir</code> to check existence before calling <code>GetAttr</code> if unsure</li>
<li>For multiple files, consider caching attribute values</li>
<li>Network paths may be slower than local paths</li>
<li>Accessing removable media can cause delays if not present</li>
</ul>
<h1 id="best-practices">Best Practices</h1>
<ol>
<li><strong>Always use error handling</strong> - file may not exist</li>
<li><strong>Use bitwise AND</strong> to test individual attributes</li>
<li><strong>Check Dir first</strong> if file existence is uncertain</li>
<li><strong>Cache results</strong> when checking attributes repeatedly</li>
<li><strong>Use constants</strong> (vbReadOnly, etc.) instead of numeric values</li>
<li><strong>Handle network paths carefully</strong> - may be unavailable</li>
<li><strong>Don't assume attributes</strong> - always check explicitly</li>
</ol>
<h1 id="comparison-with-other-functions">Comparison with Other Functions</h1>
<h2 id="getattr-vs-filelen"><code>GetAttr</code> vs <code>FileLen</code></h2>
<pre><code class="language-vbnet">&#x27; GetAttr - Returns file attributes
attr = GetAttr(&quot;file.txt&quot;)  &#x27; Returns attribute flags
&#x27; FileLen - Returns file size
size = FileLen(&quot;file.txt&quot;)  &#x27; Returns size in bytes</code></pre>
<h2 id="getattr-vs-dir"><code>GetAttr</code> vs <code>Dir</code></h2>
<pre><code class="language-vbnet">&#x27; GetAttr - Gets attributes of specific file
attr = GetAttr(&quot;file.txt&quot;)
&#x27; Dir - Searches for files matching pattern
filename = Dir(&quot;*.txt&quot;, vbNormal)</code></pre>
<h2 id="getattr-vs-filedatetime"><code>GetAttr</code> vs <code>FileDateTime</code></h2>
<pre><code class="language-vbnet">&#x27; GetAttr - Returns attributes
attr = GetAttr(&quot;file.txt&quot;)
&#x27; FileDateTime - Returns modification date/time
dt = FileDateTime(&quot;file.txt&quot;)</code></pre>
<h1 id="limitations">Limitations</h1>
<ul>
<li>Returns Integer (limited to values 0-32767 due to VB6 Integer type)</li>
<li><code>vbAlias</code> only works on Macintosh systems</li>
<li>Cannot set attributes (use <code>SetAttr</code> for that)</li>
<li>No support for extended attributes or NTFS features</li>
<li>Limited to file system attributes only</li>
<li>Does not provide security descriptor information</li>
</ul>
<h1 id="bitwise-operations">Bitwise Operations</h1>
<p>Testing for specific attributes:</p>
<pre><code class="language-vbnet">&#x27; Test if read-only
If (attr And vbReadOnly) Then &#x27; Has read-only attribute
&#x27; Test if NOT read-only
If Not (attr And vbReadOnly) Then &#x27; Doesn&#x27;t have read-only
&#x27; Test for multiple attributes
If (attr And (vbReadOnly Or vbHidden)) Then &#x27; Has either attribute
&#x27; Test for exact attribute combination
If attr = (vbReadOnly Or vbHidden) Then &#x27; Has exactly these two</code></pre>
<h1 id="related-functions">Related Functions</h1>
<ul>
<li><code>SetAttr</code> - Sets the attributes of a file</li>
<li><code>Dir</code> - Returns a file or directory name matching a pattern</li>
<li><code>FileLen</code> - Returns the length of a file in bytes</li>
<li><code>FileDateTime</code> - Returns the date and time a file was created or last modified</li>
<li><code>FileAttr</code> - Returns the file mode or file handle for an open file</li>
<li><code>FileExists</code> - Checks if a file exists (custom function using Dir)</li>
</ul>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to File</a> |
                <a href="../index.html">View all functions</a>
            </p>
        </div>

    </main>

    <footer>
        <div class="container">
            <p>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>