Imports System Imports System.IO
Public Class Form1
Dim Str_FullPath As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button2.Enabled = False CheckBox1.Enabled = False CheckBox2.Enabled = False CheckBox3.Enabled = False End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Call resetcbox() OpenFileDialog1.Title = "Browse the file" OpenFileDialog1.Filter = "All files (*.*)|*.*" If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Str_FullPath = OpenFileDialog1.FileName Label2.Text = Str_FullPath 'to get information size of a file using fileinfo Dim ukuran As New FileInfo("" & Str_FullPath & "") Label5.Text = ukuran.Length.ToString + " bytes" Dim buat As String 'to get information creation time of a file using getcreationtime buat = File.GetCreationTime("" & Str_FullPath & "") Label7.Text = buat If (File.GetAttributes("" & Str_FullPath & "") And FileAttributes.ReadOnly) = FileAttributes.ReadOnly Then CheckBox1.Checked = True End If If (File.GetAttributes("" & Str_FullPath & "") And FileAttributes.Hidden) = FileAttributes.Hidden Then CheckBox2.Checked = True End If If (File.GetAttributes("" & Str_FullPath & "") And FileAttributes.System) = FileAttributes.System Then CheckBox3.Checked = True End If CheckBox1.Enabled = True CheckBox2.Enabled = True CheckBox3.Enabled = True End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If MsgBox("Are you sure want to apply change ?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then If CheckBox1.Checked = True And CheckBox2.Checked = False And CheckBox3.Checked = False Then 'to set file attribute readonly File.SetAttributes("" & Str_FullPath & "", FileAttributes.ReadOnly) ElseIf CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = False Then 'to set file attribute readonly and hidden File.SetAttributes("" & Str_FullPath & "", FileAttributes.ReadOnly + FileAttributes.Hidden) ElseIf CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True Then 'to set file attribute readonly ,hidden and system File.SetAttributes("" & Str_FullPath & "", FileAttributes.ReadOnly + FileAttributes.Hidden + FileAttributes.System) ElseIf CheckBox1.Checked = False And CheckBox2.Checked = True And CheckBox3.Checked = False Then File.SetAttributes("" & Str_FullPath & "", FileAttributes.Hidden) 'to set file attribute hidden ElseIf CheckBox1.Checked = False And CheckBox2.Checked = True And CheckBox3.Checked = True Then 'to set file attribute hidden and system File.SetAttributes("" & Str_FullPath & "", FileAttributes.Hidden + FileAttributes.System) ElseIf CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = True Then 'to set file attribute system File.SetAttributes("" & Str_FullPath & "", FileAttributes.System) ElseIf CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False Then 'to set file attribute normal File.SetAttributes("" & Str_FullPath & "", FileAttributes.Normal) End If Else Exit Sub End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Button2.Enabled = True End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged Button2.Enabled = True End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged Button2.Enabled = True End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click MsgBox("文件属性修改") End Sub End Class
|