文件属性值 [英] File Attribute Values
问题描述
我正在尝试使用System.IO.File.GetAttributes(filename)了解返回的值
如果我获取显示在资源管理器中的随机文件,则选中的框为只读& ;;文件准备存档
如果枚举的结果是
C:\ Users \ Public \ Wireshark IP Map a01688 \ ipmap.html的文件属性为:
8
2
2
5
取消选中这2个框,以便不选中任何一个,我又回来了,
C:\ Users \ Public \ Wireshark IP Map a01688 \ ipmap.html的文件属性为:
8
1
9
2
该文件的副本,仅带有加密的已检查退货,
C:\ Users \ Public \ Wireshark IP Map a01688 \ ipmap的文件属性-Encrypted.html是:
2
4
5
7
6
加密后的同一副本,文件可供存档,为该文件编制索引以加快搜索速度.返回.
C:\ Users \ Public \ Wireshark IP Map a01688 \ ipmap的文件属性-Encrypted.html是:
1
6
4
1
6
我找不到任何挑衅性的说法,这就是这个数字的意思.
我尝试使用case语句并在此处使用值
http://msdn.microsoft.com/zh-CN /library/system.io.fileattributes(v=vs.90).aspx [
无论哪种方式,如果我从0或1开始索引都没有意义.
重新使用的内容也似乎与该页面上定义的内容不符.
http://msdn.microsoft.com/zh-CN /library/windows/desktop/gg258117(v=vs.85).aspx [
I''m trying to understand the returned values using System.IO.File.GetAttributes(filename)
If I take a random file that shows in explorer the Boxes Checked are Read only & File Ready For Archiving
The Result If you enumerate are
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap.html Are :
8
2
2
5
Unchecking those 2 boxes so None are checked I get back,
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap.html Are :
8
1
9
2
A copy of the file with only encrypted checked returns,
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap - Encrypted.html Are :
2
4
5
7
6
Same Copy With encrypted,File ready for archiving ,index this file for faster searching. returns.
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap - Encrypted.html Are :
1
6
4
1
6
I can not find anything that defiantly says this is what this number means.
I tried using a case statement and using the Values here
http://msdn.microsoft.com/en-us/library/system.io.fileattributes(v=vs.90).aspx[^]
I assumed that it would start at 1 and go from there, but during a test of several files it returned a value of "0".
Either way if I start index at 0 or 1 results don''t make sense.
The reuslts also do not appear to match up to what is defined on this page.
http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx[^]
Would someone please point me in the right direction.
Thank you for any help.
Code used to produce the results:
Imports System
Imports System.IO
Imports System.Security.AccessControl
Imports System.Text
Private Sub btnGetFileAttributes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFileAttributes.Click
Dim filename As String = Nothing
Try
Dim strBuilder As New StringBuilder
Dim Attributes As String = System.IO.File.GetAttributes(filename)
For Each atb In Attributes
strBuilder.AppendLine(atb)
Next
Dim OutputString As String
OutputString = ("File Attributes for " & filename & " Are :" & vbNewLine & strBuilder.ToString)
TextBox1.Text = OutputString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
推荐答案
您需要查看System.IO.FileAttributes
的定义以了解这一简单内容.他们提供了一个位集:
You need to see at the definition of theSystem.IO.FileAttributes
to understand this simple thing. They present a bitset:
ReadOnly = 1,<br />
Hidden = 2,<br />
System = 4,<br />
Directory = 16
...
要将属性添加到位集中,您需要使用二进制Or
操作.要检查是否设置了属性,您需要执行二进制And
并将结果与0比较(这意味着该位是清除的).
有关按位运算,请参见:
http://msdn.microsoft.com/en-us/library/wz3k228a%28v = vs.80%29.aspx [ ^ ].
另请参见: http://en.wikipedia.org/wiki/Bitset [
…
To add an attribute to a bitset, you need to use binary Or
operation. To check if an attribute is set, you need to perform binary And
and compare the result with 0 (which means the bit is clear).
For bitwise operations, please see:
http://msdn.microsoft.com/en-us/library/wz3k228a%28v=vs.80%29.aspx[^].
See also: http://en.wikipedia.org/wiki/Bitset[^].
这里是我现在所拥有的:
Here Is what I have now:
Private Sub btnGetFileAttributes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFileAttributes.Click
'Attribute Info From http://msdn.microsoft.com/en-us/library/system.io.fileattributes(v=vs.90).aspx
TextBox1.Clear()
Dim filename As String = Nothing
Try
If UseFileBorowser = True Then
filename = FN
If filename = Nothing Then
MsgBox("No File Was Chosen")
Exit Sub
End If
ElseIf UseFileBorowser = False Then
filename = TextBox2.Text
If filename = Nothing Then
MsgBox("No File Path Was Entered")
Exit Sub
End If
End If
'Dim flatb As FileAttribute
Dim strBuilder As New StringBuilder
filename = OpenFileDialog1.FileName
Dim FileAtri As FileAttribute '.ToString
For idx = 0 To 65536
FileAtri = idx
If idx <> System.IO.File.GetAttributes(filename) = False Then
'strBuilder.AppendFormat("{0,3} - {1}", idx, CType(Val(FileAtri), FlagAttr).ToString())
strBuilder.AppendLine()
strBuilder.AppendLine(CType(Val(FileAtri), FlagAttr).ToString() & vbNewLine)
End If
Next
Dim OutputString As String
OutputString = ("File Attributes for " & filename & " Are :" & vbNewLine & strBuilder.ToString)
'OutputString = (Attributes.ToString)
TextBox1.Text = OutputString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
<flagsattribute()> _
Enum FlagAttr As Integer
FILE_ATTRIBUTE_ARCHIVE = 32
FILE_ATTRIBUTE_COMPRESSED = 2048
FILE_ATTRIBUTE_DEVICE = 64
FILE_ATTRIBUTE_DIRECTORY = 16
FILE_ATTRIBUTE_ENCRYPTED = 16384
FILE_ATTRIBUTE_HIDDEN = 2
FILE_ATTRIBUTE_NORMAL = 128
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192
FILE_ATTRIBUTE_OFFLINE = 4096
FILE_ATTRIBUTE_READONLY = 1
FILE_ATTRIBUTE_REPARSE_POINT = 1024
FILE_ATTRIBUTE_SPARSE_FILE = 512
FILE_ATTRIBUTE_SYSTEM = 4
FILE_ATTRIBUTE_TEMPORARY = 256
FILE_ATTRIBUTE_VIRTUAL = 65536
End Enum
File with just Read only Checked
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap.html Are :
FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
File With Just Encrypted Checked"
File Attributes for C:\Users\Public\Wireshark IP Map a01688\ipmap - Encrypted.html Are :
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, FILE_ATTRIBUTE_ENCRYPTED
Stil无法完全按照我的意愿输出,但似乎返回正确的值.
Stil Does not ouput exactly the way I would Like but Appears to return the Correct Values.
这篇关于文件属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!