Public Class Form1
之前加上
Imports System.IO
窗体设计界面:
获得文件相关信息:
Private Sub btnChooseFolder_Click(sender As Object,e As EventArgs) Handles btnChooseFile.Click If OpenFileDialog1.ShowDialog <> DialogResult.OK Then Exit Sub End If Dim FilePath As String = OpenFileDialog1.FileName Dim file As New FileInfo(FilePath) txtFileInfo.Text = "" txtFileInfo.Text &= "文件名称:" & file.Name & ControlChars.CrLf txtFileInfo.Text &= "文件路径:" & file.FullName & ControlChars.CrLf txtFileInfo.Text &= "扩展名:" & file.Extension & ControlChars.CrLf txtFileInfo.Text &= "文件大小:" & file.Length & "字节" & ControlChars.CrLf txtFileInfo.Text &= "创建日期:" & file.CreationTime.ToString("yyyy-MM-dd") & ControlChars.CrLf txtFileInfo.Text &= "修改日期:" & file.LastWriteTime.ToString("yyyy-MM-dd") & ControlChars.CrLf txtFileInfo.Text &= "属性:" & getFolderAttr(file.Attributes) & ControlChars.CrLf End Sub
Function getFolderAttr(ByVal attr As Integer) As String Dim strAttr As String = "" If (attr And FileAttributes.Archive) Then strAttr &= " 备份" If (attr And FileAttributes.Compressed) Then strAttr &= " 压缩" If (attr And FileAttributes.Directory) Then strAttr &= " 目录" If (attr And FileAttributes.Encrypted) Then strAttr &= " 加密" If (attr And FileAttributes.Hidden) Then strAttr &= " 隐藏" If (attr And FileAttributes.Normal) Then strAttr &= " 正常" If (attr And FileAttributes.Offline) Then strAttr &= " 脱机" If (attr And FileAttributes.ReadOnly) Then strAttr &= " 只读" If (attr And FileAttributes.System) Then strAttr &= " 系统" If (attr And FileAttributes.Temporary) Then strAttr &= " 临时" Return strAttr End Function
学习更多vb.net知识,请参看
vb.net 教程 目录
原文链接:https://www.f2er.com/vb/256549.html