■■■

2016年4月8日金曜日

ファイルから読み取り属性や隠しファイル属性を取得する方法

ファイルから読み取り属性や隠しファイル属性を取得する方法
VB.NET
        ' 初期化
        Dim faFileInfo As System.IO.FileAttributes = System.IO.File.GetAttributes("C:\finfo.txt")

        ' 読取り属性を判定する
        If (faFileInfo And System.IO.FileAttributes.[ReadOnly]) = System.IO.FileAttributes.[ReadOnly] Then
            MessageBox.Show("読み取り専用です")
        End If

        ' 隠しファイル属性を判定
        If (faFileInfo And System.IO.FileAttributes.Hidden) = System.IO.FileAttributes.Hidden Then
            MessageBox.Show("隠しファイルです")
        End If



C#
            // 初期化
            System.IO.FileAttributes faFileInfo = System.IO.File.GetAttributes(@"C:\finfo.txt");

            // 読取り属性を判定する
            if ((faFileInfo & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly)
            {
                MessageBox.Show("読み取り専用です");
            }

            // 隠しファイル属性を判定
            if ((faFileInfo & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
            {
                MessageBox.Show("隠しファイルです");

            }

■■■