VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
ファイルの属性を取得するにはFileクラスのGetAttributesメソッドを使用します。
ファイルの属性を設定するにはFileクラスのSetAttributesメソッドを使用します。
Dim filepath As String = "C:\Work\Test.txt" Dim FileAttr As New System.IO.FileAttributes FileAttr = System.IO.File.GetAttributes(filepath) If (FileAttr And IO.FileAttributes.Compressed) = IO.FileAttributes.Compressed Then Console.WriteLine("ファイルは圧縮されています") End If If (FileAttr And IO.FileAttributes.Directory) = IO.FileAttributes.Directory Then Console.WriteLine("このファイルはディレクトリです") End If If (FileAttr And IO.FileAttributes.Encrypted) = IO.FileAttributes.Encrypted Then Console.WriteLine("このファイルは暗号化されています") End If If (FileAttr And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then Console.WriteLine("このファイルは隠しファイルです") End If If (FileAttr And IO.FileAttributes.ReadOnly) = IO.FileAttributes.ReadOnly Then Console.WriteLine("このファイルは読み取り専用です") End If If (FileAttr And IO.FileAttributes.System) = IO.FileAttributes.System Then Console.WriteLine("このファイルはシステムファイルです") End If If (FileAttr And IO.FileAttributes.Temporary) = IO.FileAttributes.Temporary Then Console.WriteLine("このファイルは一時ファイルです") End If
Dim filepath As String = "C:\Work\Test.txt" '読み取り属性をセットする System.IO.File.SetAttributes(filepath, IO.File.GetAttributes(filepath) Or IO.FileAttributes.ReadOnly)