除了@R_404_6852@Info外,.net还提供了@R_404_6852@类来 *** 作文件, 就像Directory与DirectoryInfo是一对类似的类,@R_404_6852@和@R_404_6852@Info也很像,同样,不同于@R_404_6852@Info,@R_404_6852@没有提供属性,只有方法,而且方法是静态的,也就是直接可以用的。 还是之前的话,哪个用着简单就用哪个。
也是和《 vb.net 教程 4-3 文件 *** 作 FileInfo 1 》中类似的窗体来说明@R_404_6852@类的使用:
主要的代码: 获得文件信息,和介绍@R_404_6852@Info时的代码差不多:
Private Sub btnChoose@R_404_6852@_Click(sender As Object,e As EventArgs) Handles btnChoose@[email protected] If Open@[email protected] <> DialogResult.OK Then Exit Sub End If Dim @R_404_6852@Path As String = Open@R_404_6852@Dialog1.@R_404_6852@name txt@[email protected] = "" txt@[email protected] &= "文件路径:" & @R_404_6852@Path & ControlChars.CrLf txt@[email protected] &= "创建日期:" & @[email protected](@R_404_6852@Path).ToString("yyyy-MM-dd") & ControlChars.CrLf txt@[email protected] &= "修改日期:" & @[email protected](@R_404_6852@Path).ToString("yyyy-MM-dd") & ControlChars.CrLf txt@[email protected] &= "属性:" & getFolderAttr(@[email protected](@R_404_6852@Path)) & ControlChars.CrLf End Sub Function getFolderAttr(ByVal attr As Integer) As String Dim strAttr As String = "" If (attr And @[email protected]) Then strAttr &= " 备份" If (attr And @[email protected]) Then strAttr &= " 压缩" If (attr And @[email protected]) Then strAttr &= " 目录" If (attr And @[email protected]) Then strAttr &= " 加密" If (attr And @[email protected]) Then strAttr &= " 隐藏" If (attr And @[email protected]) Then strAttr &= " 正常" If (attr And @[email protected]) Then strAttr &= " 脱机" If (attr And @[email protected]) Then strAttr &= " 只读" If (attr And @[email protected]) Then strAttr &= " 系统" If (attr And @[email protected]) Then strAttr &= " 临时" Return strAttr End Function设置文件属性:
Private Sub btnAttr_Click(sender As Object,e As EventArgs) Handles btnAttr.Click Dim @R_404_6852@path As String = "d:\bb.jpg" If @[email protected](@R_404_6852@path) = False Then Exit Sub Dim attr As Integer = @[email protected](@R_404_6852@Path) If (attr And @[email protected]) = @[email protected] Then If cbReadonly.Checked = False Then attr = attr Xor @[email protected] Else If cbReadonly.Checked = True Then attr = attr Or @[email protected] End If If (attr And @[email protected]) = @[email protected] Then If cbHIDden.Checked = False Then attr = attr Xor @[email protected] Else If cbHIDden.Checked = True Then attr = attr Or @[email protected] End If If (attr And @[email protected]) = @[email protected] Then If cbSys.Checked = False Then attr = attr Xor @[email protected] Else If cbSys.Checked = True Then attr = attr Or @[email protected] End If @[email protected](@R_404_6852@path,attr) End Sub
嗯,学到这里。这下可以用代码恢复被优盘病毒修改为系统、隐藏的文件了,不需要再在cmd下敲attrib了。
学习更多vb.net知识,请参看 vb.net 教程 目录 总结
以上是内存溢出为你收集整理的vb.net 教程 4-5 文件 *** 作 File 1全部内容,希望文章能够帮你解决vb.net 教程 4-5 文件 *** 作 File 1所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)