■■■

2016年4月8日金曜日

ファイル属性を設定する方法

ファイル属性を設定する方法
VB.NET
        ' ファイル
        Const STR_PATH As String = "C:\fileinfo.txt"

        ' 属性の取得
        Dim fiFileInfo As System.IO.FileAttributes = System.IO.File.GetAttributes(STR_PATH)

        ' 読み取り専用属性を設定する

        System.IO.File.SetAttributes(STR_PATH, fiFileInfo Or System.IO.FileAttributes.[ReadOnly])

C#
            // ファイル
            const string STR_PATH = @"C:\fileinfo.txt";

            // 属性の取得
            System.IO.FileAttributes fiFileInfo = System.IO.File.GetAttributes(STR_PATH);

            // 読み取り専用属性を設定する

            System.IO.File.SetAttributes(STR_PATH, fiFileInfo | System.IO.FileAttributes.ReadOnly);

■■■